HashMap<String, String> apos = new HashMap<String, String>();
apos.put("i'm","I am");
apos.put("can't","cannot");
apos.put("couldn't","could not");
String[] st = new String[]{"i'm","johny"};
Iterator itr = apos.entrySet().iterator();
for (int i = 0; i < st.length; i++) {
while((itr).hasNext()) {
if (itr.equals(st[i]))
{
st[i].replace(st[i],??????(value of the matched key))
}
}
}
我想将一个字符串与 hashmap 进行比较,如果它与它的键匹配,则用 hashmap 值替换一个单词。以上是我想要做的。谁能帮我写什么来代替钥匙。
帮助将不胜感激。谢谢