我有一张地图:
Map<String, String> ht = new HashMap();
Run Code Online (Sandbox Code Playgroud)
我想知道如何搜索它并找到与特定字符串匹配的任何内容.如果它是匹配存储它成为arraylist.地图包含这样的字符串:
1,2,3,4,5,5,5
匹配的字符串为5.
所以我有这个:
String match = "5";
ArrayList<String> result = new ArrayList<String>();
Enumeration num= ht.keys();
while (num.hasMoreElements()) {
String number = (String) num.nextElement();
if(number.equals(match))
{
result.add(number);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7826 次 |
| 最近记录: |