I\'m just wondering how to check if TreeMap> contains a value in Java? For Example:
/*I have TreeMap> map with these element
You're testing to see whether the map contains a String, "square"-- but the values in your map are ArrayList<String> objects.
If you know that you're looking for a shape, you can first get the "shape" list, and test to see whether it contains the specific shape "square".
ArrayList<String> shapes = map.get("shape");
boolean containsSquare = shapes.contains("square");
public boolean valueExists(String value){
for(Map.Entry<String,ArrayList<String>> entry : treeMap.entrySet()) {
String key = entry.getKey();
ArrayList<String> values = entry.getValue();
for (String str:values){
if (value.equals(str)){
return true;
}
}
}
return false;
}
Something like below would work
Map<String,ArrayList<String>> map=new TreeMap<String, ArrayList<String>>();
Collection<ArrayList<String>> values=map.values();
for(ArrayList<String> list:values)
{
list.contains("text_to_search")
{
}
}