import java.util.*;Output:
public class Recherche_valeur_treemap {
public static void main(String[] args) {
// creating TreeMap
TreeMap< String, String> treemap = new TreeMap< String, String> ();
// insert into treemap
treemap.put("1", "a");
treemap.put("2", "b");
treemap.put("3", "c");
treemap.put("4", "d");
treemap.put("5", "e");
//display key elements and value
Set set=treemap.keySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
String key = ((String) iterator.next());
String val = ((String) treemap.get(key));
System.out.println(key+"-> "+val);
}
boolean exists = treemap.containsValue("a");
System.out.println("the value a exists in the list: "+exists);
exists = treemap.containsValue("f");
System.out.println("the f value exists in the list: "+exists);
}
}
1-> aReferences:
2-> b
3-> c
4-> d
5-> e
the a value exists in the list: true
the f value exists in the list: false
Please disable your ad blocker and refresh the window to use this website.