Results 1 to 1 of 1
Thread: Sorting Elements in a TreeMap
-
Sorting Elements in a TreeMap
Java Code: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)); } } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
How to use treemap
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:47 PM -
using elements from other classes
By Camden in forum New To JavaReplies: 1Last Post: 03-21-2008, 07:25 AM -
Help with Sorting Program
By rhm54 in forum New To JavaReplies: 3Last Post: 01-25-2008, 10:08 PM -
Elements package
By BlitzA in forum New To JavaReplies: 0Last Post: 12-27-2007, 11:58 PM -
sorting JTable
By mansi_3001 in forum Advanced JavaReplies: 3Last Post: 08-10-2007, 06:29 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks