我需要将一个句子分成两个字符串,第一个字符串存储为键,第二个字符串存储为HashMap中的值。例如:
String sent="4562=This is example";
这是我的句子,我使用以下行将其分成两个字符串:
sent.split("=");
我想将第一个字符串(4562
)存储为键,将第二个字符串存储为HashMap中的值。
您能否分享您的想法或问题解决方案?
您正在陈述自己的答案:
HashMap<String, String> map = new HashMap<String, String>(); //initialize the hashmap
String s = "4562=This is example"; //initialize your string
String[] parts = s.split("="); //split it on the =
map.put(parts[0], parts[1]); //put it in the map as key, value
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句