I have an Array
in Java
with several elements, what I am doing is Iterating and displaying all the elements of the Array that are different from null.
This is the Demo
:
public class TestData {
public static void main(String[] args) {
String firstArg[] = new String[5];
firstArg[2] = "arg2";
firstArg[4] = "arg4";
for (String a: firstArg) {
if (a != null) {
System.out.println(a);
}
}
}
}
My problem: is it possible to iterate the elements other than null in a single line?