Why not do a for loop with if statement.
put this into the JSP but change 'array' to you array name.
<%
//go through the array to check all the values
for(int i=0; i<array.length();i++){
//If array is null, nothing happen
if(array==null){
//leave here blank
}
//If array not null, then print value in a new line
else{
out.print(array+"<br>");
}
}
%>
Does that help?
>Thank you but because I am new in programming what do you mean to use continue. Can you explain it a little bit further?
<%
//go through the array to check all the values
for(int i=0; i<array.length();i++) {
//If array is null, nothing happen
if(array==null){
//leave here blank; instead use continue like:
//this will skip the statements next to it, and increments the value of i in for loop and continues to execute the body of for loop.
//The same will be repeated till the last iteration.
continue;
}
//If array not null, then print value in a new line
else{
out.print(array+"<br>"); //don't change the logic here
}
}
%>
If you want to delete the null values during preprocessing, do:
String[] array = {"value1", "value2", null, "value4", null};
String[] remove = {null};
List list = new ArrayList(Arrays.asList(array));
list.removeAll(new ArrayList(Arrays.asList(remove)));
array = (String[]) list.toArray(new String[list.size()]);
Or, better use List or Set all the time instead of String[]. The List and Set provides much more useful functions.
Otherwise, if you want to skip the null values during displaying, then indeed use continue; when value == null.