Source Code : Sort keys in an Hashtable
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Sort keys in an Hashtable
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
public class Main {
public static void main(String args[]) {
Hashtable<String, String> h = new Hashtable<String, String>();
h.put("a", "b");
h.put("c", "d");
h.put("e", "f");
for (String str : h.keySet()) {
System.out.println(str);
}
List<String> v = new ArrayList<String>(h.keySet());
Collections.sort(v);
for (String str : v) {
System.out.println(str + " " + (String) h.get(str));
}
}
}
Thank with us