Hello, previously you helped me with this part 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]);
}
}
}
Which now I have this small detail: I would like the statement if(toList.contains(","))
to be repeated every time the comma (,) is not inserted. Since the message "Falta el carácter coma (,) por favor ingreselo:"
is repeated only once, I know that it must return a loop, but the command which is while
. Please help me.
It should be inside the while loop, try the following:
Of course, if you want each message to be seen separately, otherwise alanfcm's response is enough.
Based on the question:
I leave you the following answer:
You can do it like this:
You could make use of a loop
do-while
to validate what the user entered. With this loop you will be able to make it run at least once and if in the validation of what the user entered it turns out that they must enter information again, then the cycle is repeated. You can also make use of boolean variables to store the result of the validations.The code proposed with
do-while
is the following:In this way, it first allows the user to enter a text string and will store it in the variable
toList
, then it will check if it is empty or null and store the result in the variableestaVacio
, then it will check if the entered string contains any comma characters and the result will store it in the variableconteienComa
, in both cases an error message is printed. If everything is correct, itCorreoUtilBuffereader1.Lista(toList);
will execute the line and exit the loop.At the end of everything, the loop
do-while
evaluates the previous booleans and these determine if it is executed again. That is, after having validated, if at the end of the loop the string is empty or does not contain a comma, then it is repeated again.