I have a string but cannot parse it into Map
string s="sakib hasan : 3 : sumon ali : 4 : tutul : 100
I need to create a HashMap from above string. sakib hasan,sumon ali,tutul,shila akter should be KEY of HashMap and 3,4,100,1, should be VALUEs of KEYs.
I have tried with the flowing code but unable to solve the problem
Map<String, Integer>amap=new HashMap<String,Integer>();
String[] splt=s.split(":");
for (String string : splt)
{
String[] pair=string.split(" ");
amap.put(pair[0])+Integer.parseInt(pair[1]);
}
Is there a way can I do this without hard coding
stringin each iteration and it should help you solve this problem, as well as other problems you may encounter in the future.