import java.util.*;The execution of this code gives:
public class recherche_treemap {
public static void main(String[] args) {
// creating TreeMap
TreeMap< String, String> treemap_langue = new TreeMap< String, String> ();
// insertion in treemap
treemap_langue.put("fr", "français");
treemap_langue.put("en", "English");
treemap_langue.put("es", "Spanish");
treemap_langue.put("it", "Italian");
treemap_langue.put("ge", "German");
//browse keys with Iterator
System.out.println("Code List");
Set set=treemap_langue.keySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
String key = ((String) iterator.next());
System.out.println(key);
}
boolean exists = treemap_langue.containsKey("es");
System.out.println("the es key exists in the list: "+exists);
String value = treemap_langue.get("en");
System.out.println("en is the code for: "+value);
}
}
Code ListReferences:
en
es
fr
ge
it
the es key exists in the list: true
en is the code for: english
Please disable your ad blocker and refresh the window to use this website.