0

I have a String as follows :

s = "['a','b','c']"

How can i convert this string into List Object..??

3 Answers 3

5

You could do something like

s = s.replace("[", "").replace("]", "");
String[] split = s.split(",");
List<String> list = Arrays.asList(split);
Sign up to request clarification or add additional context in comments.

Comments

2
  1. Remove brackets

  2. String.split() using , separator

  3. For each item remove quotes (')

  4. No 4th point

1 Comment

And for bracket removal - String.substring(startIndex, endIndex)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.