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);
}
}
Not quite sure if I understand you, but I guess you are looking for containsKey
?
ht.containsKey("5");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With