-5

Trying to call the java file, and have been asked to make it so that if args[0] is empty in a terminal call, it should return all objects. Cant get it working without getting an error.

else if(args[1]==null){
            System.out.println("Printing information on all cars.");
                for (Bil l : bilArrayList){
                    System.out.println(l.toString());
                }

        }
Dank meme
  • 11
  • 4

1 Answers1

1

Without knowing the details of your code, I would suggest you to check the size of args first:

if(args.length> 0) { 
//It depends on the size of the argument you wanna check. 
//Might be args.length > 1 if you wanna make sure at least 2 elements in the args array
   //doSomething
} else {
  //doSomethingElse
}
Shawn Xiong
  • 470
  • 3
  • 14
  • args[1] means the second value, so you should check args.length > 1 if you want to get args[1]. Please note that you have args[0] and then args[1] – Piotr0123456 Feb 16 '17 at 10:11
  • @Piotr0123456 the OP's requirement looks bit confusing. In the question it said "if args[0] is empty in a terminal call, it should return all objects". But the code checks `args[1]`. – Shawn Xiong Feb 16 '17 at 10:15
  • yes, I agree that "the OP's requirement looks bit confusing". The full `main()` method would be very helpful here. We don't know the details... – Piotr0123456 Feb 16 '17 at 10:29