Skip to content
Advertisement

Tag: arraylist

Sort List of Strings arrays in Java

I’m trying to make a program that consists of an array of Strings . now I need to sort them in order ‘PJ’, ‘GHS’, ‘FJ’, ‘PAS’ and date. input : output: //Always ‘PJ’, ‘GHS’, ‘FJ’ then ‘PAS’ Answer You should consider using custom java classes instead of String Array. Find below an example to do it .

How to search in arrayList then change?

So i’m making a supermarket program that allows to add products and sell them, so far i have this: I´d like to know how to search in Product list by name and then change the stock(subtract-n) to sell n of that product. Answer You can use Stream API to find out the product by name. Filter the list by checking

Cannot invoke ” ” because array is null

I need to add information about 2 actors such as their name, address and age and have done so without arrays easily but it’s necessary, I keep getting the error “Cannot invoke “TestActor.setName(String)” because “actors[0]” is null at TestMain.main(TestMain.java:5)” This is just a test main I’m using to test it ”’ And this is the actor class I’m using that

Advertisement