Sorting Elements in a TreeMap : HashTable Map : Collections Data Structure : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Collections Data Structure   » [  HashTable Map  ]  Screenshots 
 



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[] 4800f12103.6f12756.3f6794f142984f,
        120536f51118f49532f2274f };
    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));
    }
  }
}
           
       
Related examples in the same category
1.  Associates keys with values Associates keys with values
2.  A simple Map implementation A simple Map implementation
3.  Hash table with separate chaining
4.  Hash table with linear probing Hash table with linear probing
5.  Hash table with double hashing Hash table with double hashing
6.  Working with Key-Value Pairs in a Hashtable
7.  Demonstrate the Hashtable class, and an Enumeration
8.  Demonstrate the HashMap class, and an Iterator Demonstrate the HashMap class, and an Iterator
9.  Soft HashMap
10.  MultiMap extends AbstractMap
11.  Array Map extends AbstractMap Array Map extends AbstractMap
12.  Demonstrating the WeakHashMap Demonstrating the WeakHashMap
13.  Use treemap Use treemap
14.  What you can do with a TreeMap What you can do with a TreeMap
15.  A Map implemented with ArrayLists
16.  Simple demonstration of HashMap Simple demonstration of HashMap
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.