Java split a string into ArrayList I want to split the following String into java ArrayList

"[\"1-72\",\"1-111\",\"1-4\"]"

I had wrote a very rough solution but not sure how to enhance it:

String sample = "\"[\"1-72\",\"1-111\",\"157f9d3dfb4-4\"]\"";
sample =  sample.replaceAll("\"", "");      //to replace double quote
sample = sample.replaceAll("\\[", "").replaceAll("\\]","");    //to replace open and close square bracket
List&lt;String&gt; sampleList= Arrays.asList(sample.split(","));
sampleList.forEach(System.err::println);
There are many encoding formats that could lead to this string. One of them is JSON. So instead of writing the splitting code yourself, you should use one of the many existing JSON parsers. Have a look at the awesome-java project at GitHub to find one.

Then, your code should become as simple as:

JSONArray sampleList = JSON.parseArray(sample);