Lalit Dubey :
I have one String
value which I am getting from one of svo, i.e. String reply=svo.getReplies();
The output that I am getting is like --> "1:true,2:false,3:true,4:false,5:false,6:false"
Now what I want is to separate storage of the reply and store all replies in new variables for every reply. For example:
String firstVal= "true";
String secondeVal= "false";
// ... and so on.
How can I do it?
Mark :
You can make Map
from this string. And then use that map as you need.
For example: String firstVal = map.get(1);
String s1 = "1:true,2:false,3:true,4:false,5:false,6:false";
Map<Integer, String> map = new HashMap<>();
for (String s : s1.split(",")){
map.put(Integer.parseInt(s.substring(0, s.indexOf(":"))), s.substring(s.indexOf(":")+1));
}
for (Integer key : map.keySet()) System.out.println(key + " " + map.get(key));