I have the string x="Alberto; jose; Felipe; Ana". I needed to get the 2nd die, how do I do it? Thank you in advance.
obs: The string x is inside an array of strings.
I have the string x="Alberto; jose; Felipe; Ana". I needed to get the 2nd die, how do I do it? Thank you in advance.
obs: The string x is inside an array of strings.
"Alberto;jose;Felipe;Ana".split(";")[1];
"split" returns an array with all strings resulting from the "break" in the character passed by parameter.
To get data from a separate string by "; " you can use the split
method of the string variable itself.
Example:
String x = "Alberto;jose;Felipe;Ana";
String[] dadosSeparados = x.split(";");
for(String s : dadosSeparados){
System.out.println("dado : "+s);
}
Use the split function of the string class.
String frase = "Alberto;jose;Felipe;Ana";
String[] array = frase.split(";");