0
How I split a string input in java?
Basically, I want to split the user input and then use each entity seprately.For example if user enter abcd then I want to split each character and then use it as I wish.One way that I knows is using next.charAt() but I could not apply it on long strings having random space between them.
3 Respostas
+ 7
SImple
Use split funtion of java
String a = "abcd";
String[] arr = a.split("");
+ 3
This is one more way-
String str = "abcde";
char[] arr = str.toCharArray();
+ 1
There is one more way using charAt:
public class Program
{
public static void main(String[] args) {
String str = "Welcome to Javatpoint portal";
for (int i=0; i<=str.length()-1; i++) {
System.out.println("Char at "+i+" place "+str.charAt(i));
}
}
}