Reputation: 608
Given a String, say String s = "abcderfh"
;
How would you turn this into a String Array.
Thank you in Advance.....
Upvotes: 0
Views: 119
Reputation: 3742
If you would like to obtain an array of characters, you should use the toCharArray() method on the String.
So you can do this:
String s = "abcderfh";
char[] myarray = s.toCharArray()
Upvotes: 5
Reputation: 425398
If you mean an array of String, where each element is one letter, do this:
String s = "abcderfh";
String[] letters = s.split("(?<=.)"); // split after every character
System.out.println(Arrays.toString(letters));
Output:
[a, b, c, d, e, r, f, h]
Upvotes: 2
Reputation: 88
You can find a great example right here:
http://api.jquery.com/jQuery.makeArray/
Upvotes: -2