string to string array conversion in java
Posted By: Anonymous
I have a string = "name";
I want to convert into a string array.
How do I do it?
Is there any java built in function? Manually I can do it but I’m searching for a java built in function.
I want an array where each character of the string will be a string.
like char ‘n’ will be now string “n” stored in an array.
Solution
To start you off on your assignment, String.split
splits strings on a regular expression and this expression may be an empty string:
String[] ary = "abc".split("");
Yields the array:
(java.lang.String[]) [, a, b, c]
Getting rid of the empty 1st entry is left as an exercise for the reader 🙂
Note: In Java 8, the empty first element is no longer included.
Answered By: Anonymous
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.