Reputation:
I have a String as follows :
s = "['a','b','c']"
How can i convert this string into List Object..??
Upvotes: 0
Views: 11545
Reputation: 4350
Use the split()
method on s
. So, s.split(",");
will produce an String array of the following form: ["['a']", "'b'", "'c']"]
. I'll leave it to you to read the javadoc to figure out how to get exactly what you want in the array.
Once have the array, you can add all the elements to a List using the following:
List<String> list = Arrays.asList(split);
EDIT: wrote wrong method.
Upvotes: 0
Reputation: 1895
You could do something like
s = s.replace("[", "").replace("]", "");
String[] split = s.split(",");
List<String> list = Arrays.asList(split);
Upvotes: 5
Reputation: 340693
Remove brackets
String.split()
using ,
separator
For each item remove quotes ('
)
No 4th point
Upvotes: 2