+ 2
How to split the letters from a word in a string?
I actually need the answer for a project. Anybody? Or is it impossible?
6 Antworten
+ 1
You can create an array of char[] and put the letters in it.
String s = "something";
char[] letters = new char[s.length()];
For (int i = 0; i < s.length(); i++) {
letters[i] = s.charAt(i);
}
Or simply:
char[] letters = s.toCharArray();
With for loop you can also declare your array as an string array:
letters[i] = String.valueOf(s.charAt(i));
But char array saves your memory.
+ 1
In Java you can use either-
1) split();
2) toCharArray();
+ 1
Thanks
0
Yes. I am saw something different
0
Anytime!