0
String str = "[[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]";

I have a String, and want to convert it into any type either in Array,List or Object except String.

Expected Output :

 List/Array/Object =
 [[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]
3
  • java is not python, you need to split and convert it
    – Ryuzaki L
    Commented Jul 12, 2019 at 6:27
  • This is a list of lists not just a simple list. You will have to parse this string in order to convert it into what ever list like object you want. It shouldn't be hard if it is always a list of lists. Commented Jul 12, 2019 at 6:32
  • "Array,List or Object", you need to clarify what you want as your end result. Maybe add your code to the question so we understand the context better. Commented Jul 12, 2019 at 7:29

3 Answers 3

0

you have to do

List ls = Arrays.asList(str.replaceAll("\\[", "").replaceAll("\\]", "").split(","));
0

There is work around for this

1.) First replace all '[' and ']' with ""

str = str.replaceAll("[","");
str = str.replaceAll("]","");

2.)Then u can split the string with ","

which gives u an array.
String[] split = str.split(",");
0

If groups of data is important, here's an algo:

1. create new List<List<String>> strList
2. String [] strs= str.split("],")
3. loop each str in strs
  3.1 replace all existence of "[" and "]" of str
  3.2 strList.add(Arrays.asList(str.split(",")))

Hope this helps!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.