Map<String, String> hashtable = new Hashtable<>();
hashtable.put("eBook Cover Image", "724242");
hashtable.put("Cover Image", "95757");
hashtable.put("Image", "9242424");
hashtable.put("Composite", "7697979");
hashtable.put("Low-Res PDF (print)", "1111111111111111");
hashtable.put("Cover", "c11111111");
String s = "eBook Cover Image OR (Low-Res PDF (print) AND Composite)";
for (Map.Entry<String, String> m : hashtable.entrySet()) {
s = s.replace(m.getKey(), m.getValue());
}
替換未正確發生。如果密鑰與精確字符串匹配,則用字符串替換字符串
eBook c11111111 9242424 OR (1111111111111111 AND pppppppppppppppp)
你期望什麼結果? '電子書c11111111 9242424或(1111111111111111和7697979)'或者'724242或(1111111111111111和7697979)'? –
我跑你的代碼,得到:'724242或(1111111111111111和7697979)' –
724242或(1111111111111111和7697979) – user739115