import java.util.ArrayList;Output:
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
public class TriTreeMap {
public static void main(String[] args) {
//create a hashtable
Hashtableht = new Hashtable ();
//add key-value pairs
ht.put("d", "fourth");
ht.put("a", "first");
ht.put("c", "third");
ht.put("e", "fifth");
ht.put("b", "second");
System.out.println("Before sorting:");
for (Map.Entryentry : ht.entrySet())
{
System.out.println(entry.getKey());
}
//create an arraylist with the keys retrieved from hashtable
Listlistcles = new ArrayList (ht.keySet());
//sort arraylist
Collections.sort(listcles);
System.out.println("After sorting:");
for(String key:listcles)
System.out.println(cle);
}
}
Before sorting:
b
a
e
d
c
After sorting:
a
b
c
d
e
Please disable your ad blocker and refresh the window to use this website.