I have a string with the following pattern,
String test = "name=ravi,age=30,id=1;name=teja,age=32,id=2";
As you can see above, ";" is used to separate persons and "," is used to separate person's attributes and "=" to map the values of those attributes.
I would like to convert the above string into a Map<String, Map<String, String>>
where the key for the outer map is the id and the key for the inner map is the name.
Given that it is always guaranteed to have unique ids and names across the string, how do I achieve the requirement using Java regex or Java streams?
I could have done this using StringTokenizer or "split" method, but I would like to see if there is any other better way of doing this.
Edit: I have reached this far till now
List<String> persons =
Arrays.asList(test.split(";"));
List<List<String>> personAttribs =
persons.stream().map(s -> Arrays.asList(s.split(","))).collect(Collectors.toList());
I am unable to take the personAttribs and convert that to the map I am looking for.