1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/* Check if a particular value exists in Java TreeMap example This Java Example shows how to check if TreeMap object contains a particular value using containsValue method of TreeMap class. */ import java.util.TreeMap; public class CheckValueOfTreeMapExample { public static void main(String[] args) { //create TreeMap object TreeMap treeMap = new TreeMap(); //add key value pairs to TreeMap treeMap.put("1","One"); treeMap.put("2","Two"); treeMap.put("3","Three"); /* To check whether a particular value exists in TreeMap use boolean containsValue(Object key) method of TreeMap class. It returns true if the value is mapped to one or more keys in the TreeMap otherwise false. */ boolean blnExists = treeMap.containsValue("Three"); System.out.println("Three exists in TreeMap ? : " + blnExists); } } /* Output would be Three exists in TreeMap ? : true */ |
TreeMap treeMap = new TreeMap();
Hi what if I have
[code]
treeMap.put(“1″,”John”,”player”);
treeMap.put(“2″,”John”,”singer”);
treeMap.put(“3″,”Vicky”,”singer”);
[/code]
and want to check if one of the values contains string “singer”.
Is it possible to do that?
[code]
Map<integer, string=””> map = new TreeMap<integer, string=””>();
[/code]