How do you search through a map?
- by Jack Null
I have a map:
Map<String, String> ht = new HashMap();
and I would like to know how to search through it and find anything matching a particular string. And if it is a match store it into an arraylist. The map contains strings like this:
1,2,3,4,5,5,5
and the matching string would be 5.
So for I have this:
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);
}
}