I have a HashMap
HashMap<String, String> cntrlInfo = new HashMap<String, String>();
in this map some values are there I need to read the value one by one i want store the values in string.
for example {GBP,001,101,CHDP}
now I would like to store
String ccy=GBP;
how i can assign the values in string
Asked
Active
Viewed 182 times
-1

stealthjong
- 10,858
- 13
- 45
- 84

Serene
- 1
- 1
- 3
-
3It's not at all clear what's in the map. Please show a short but complete program demonstrating the problem. – Jon Skeet Sep 16 '14 at 06:36
-
private HashMap
getCntrlInfo(String reqstXml) { HashMap – Serene Sep 16 '14 at 06:59cntrlInfo = new HashMap (); now i am using Iterator It =cntrlInfo.keySet().iterator();and I would like to store each values in a separate string and want to display
1 Answers
0
import java.util.HashMap;
public class Test {
public static void main(String[] args) {
HashMap<String, String> cntrlInfo = new HashMap<String, String>();
cntrlInfo.put("A", "GBP");
cntrlInfo.put("B", "001");
cntrlInfo.put("C", "101");
cntrlInfo.put("D", "CHDP");
StringBuilder sb = new StringBuilder();
for (String val : cntrlInfo.values()) {
sb.append(val);
}
System.out.println("sb = " + sb);
String ccy = sb.substring(sb.indexOf("GBP"), sb.indexOf("GBP") + 3);
String foo = sb.substring(sb.indexOf("001"), sb.indexOf("001") + 3);
String bar = sb.substring(sb.indexOf("101"), sb.indexOf("101") + 3);
String f = sb.substring(sb.indexOf("CHDP"), sb.indexOf("CHDP") + 4);
System.out.println("ccy = " + ccy);
System.out.println("foo = " + foo);
System.out.println("bar = " + bar);
System.out.println("f = " + f);
}
}

sol4me
- 15,233
- 5
- 34
- 34
-
Thanks for your reply but I would like to store each values in a separate variable – Serene Sep 16 '14 at 07:00
-
Thanks a lot sol4me... as we can see this is the static value which we have used here but suppose i got xml where we don't know what we are going to get then how can we achieve the same. I mean in the HashMap I have xml – Serene Sep 16 '14 at 10:14