Source Code : Sorting Elements in a TreeMap
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
Sorting Elements in a TreeMap

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
public class DiameterMap {
public static void main(String args[]) {
String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter",
"Saturn", "Uranus", "Neptune", "Pluto" };
float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f,
120536f, 51118f, 49532f, 2274f };
Map map = new TreeMap();
for (int i = 0, n = names.length; i < n; i++) {
map.put(names[i], new Float(diameters[i]));
}
Iterator it = map.keySet().iterator();
Object obj;
while (it.hasNext()) {
obj = it.next();
System.out.println(obj + ": " + map.get(obj));
}
}
}
Thank with us