TreeMap: lastKey() : TreeMap : java.util : Java by API examples (example source code) Organized by topic

Java by API
C++
PHP
Java by API Home »  java.util   » [  TreeMap  ]   
 



TreeMap: lastKey()

/*
 Output:

Virginia, New York, Massachusetts

 * */

import java.util.TreeMap;

public class MainClass {
  public static void main(String args[]) {
    TreeMap map = new TreeMap();
    map.put("Virginia""Richmond");
    map.put("Massachusetts""Boston");
    map.put("New York""Albany");
    map.put("Maryland""Annapolis");

    if (!map.isEmpty()) {
      Object last = map.lastKey();
      boolean first = true;
      do {
        if (!first) {
          System.out.print(", ");
        }
        System.out.print(last);
        last = map.headMap(last).lastKey();
        first = false;
      while (last != map.firstKey());
      System.out.println();
    }
  }
}
           
       
Related examples in the same category
1.  new TreeMap < K, V > ()
2.  TreeMap: entrySet()
3.  TreeMap: firstKey()
4.  TreeMap: get(K k)
5.  TreeMap: headMap(K toKey)
6.  TreeMap: put(K k, V v)
























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