[英]String compare with keys in Map in Java
我有一个Map(String,String)和String inputText的集合。 如果其中包含Map中的任何键,您可以建议如何扫描inputText以进行检查。
例如,我有下一个:
//hashmap is used - I don't need the order
Map<String, String> mapOfStrings = new HashMap<String,String>();
mapOfStrings.put("java","yep, java is very useful!");
mapOfStrings.put("night","night coding is the routine");
String inputText = "what do you think about java?"
String outputText = ""; //here should be an <answer>
Set<String> keys = mapOfStrings.keySet();
for (String key:keys){
String value = mapOfStrings.get(key);
//here it must uderstand, that the inputText contains "java" that equals to
//the key="java" and put in outputText the correspondent value
}
我所知道的不是equals()或compareTo()。 可能是我应该以某种方式检查inptuText中字符的顺序吗?
问候
您可以使用以下内容:
for (String key:keys){
String value = mapOfStrings.get(key);
//here it must uderstand, that the inputText contains "java" that equals to
//the key="java" and put in outputText the correspondent value
if (inputText.contains(key))
{
outputText = value;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.