I have a map:
Map<String, String> ht = new HashMap();
and I would like to know how to search on it and find something matching a specific line. And if it's a coincidence store, it turns into an arraylist. The map contains the following lines:
1,2,3,4,5,5,5
and the matching line will be 5.
So, 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);
}
}
source
share