Stephan van Hulst wrote:Do you mean checking if the array has no elements, or if all elements are null?
In the first case, just check whether the length of the array is 0.
In the second case, you can use a combination of Arrays.stream(), Stream.allMatch() and Objects.isNull().
could you help me with a code?to understand better?
ekte spiriopoulos wrote:could you help me with a code?to understand better?
Ekte, you really need to try some things for yourself. We're happy to help, but we like you to ShowSomeEffort first.
1. We're still not sure exactly what you want.
2. How would YOU do it?
Try writing some code, and come back if you run into any problems.
I also suggest you have a look at our HowToAskQuestionsOnJavaRanch page.
Your code is not good. Whatever the length of the array is, this code will do nothing.
If the length is 0, the body of the for loop will not be executed.
If the length is greater than 0, the body of the loop will be executed but the if condition will not do anything.
By the way, you don't need a loop to check the length of the array. Just use the if condition.
Yes, this is what I meant. I did Google search by your subject name. Here are my findings. Then I clicked on the very top link and there is an answer in the second post from top.
ekte spiriopoulos wrote:i will try to something that isnt in my knowledges ?
Liutauras Vilda wrote:Please show us what have you tried so far after Stephan gave you couple of hints.
When you writing programs, it is common even for very experienced programmers to look up for some information on internet, that is the main tool.
As an advice, I'd suggest you to keep in your browser always opened 2 pages (these are clickable links):
1. Oracle Tutorial
2. Java API
For the time being, you should be able to find all the answers to your questions for the next few years or so. The advantage of looking information individually is, that you discover many interesting things, so you get more and more questions - so you learning
And what Winston mentioned, you need to try that out yourself first. Apart from that, everyone here in the Ranch are more than happy to help.