我有下面的代码片段。我需要找出 map 中是否有任何键可以使用折扣进行模式搜索。请帮助欣赏。
public class MapStringSearch {
public static void main(String[] args) {
Map test = new HashMap();
test.put("discount.1", 1);
test.put("discount.2", 2);
test.put("discount.3", 3);
test.put("voucher.4", 4);
}
}
最佳答案
其中一种方法是:
for ( String key : test.keySet() ) {
if(key.contains("discount"))
// do something...
else
// do something...
}
关于java - 在 HashMap 中搜索特定模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24730772/