This is the snippet of my code:
public static void Lista(String textList) {
String[]stList= textList.split(",");
Arrays.asList(stList);
for(int i = 0; i < stList.length; i++){
System.out.println("Escribe un String para convertirlo a List: ");
if((stList == null) || (stList.equals(""))){
System.out.println(" El campo que ingreso esta vacio, vuelva a ingresarlo");
}else{
System.out.println(stList[i]);
}
}
}
It is a list, which I am dealing with the If and Else commands that tells me that the field is empty and that it shows the message again: "Write a String to convert it to List: "
What happens is that in your code it does not enter the
if
since you are comparing everythingarray
to null it should have been compared with the position in which the cycle is iterating like this:stList[i]
, if you want it to ask you for the string again you can do it inside of a cyclewhile
, adapting your code a bit, it would be as follows: