Java Programing laungage

java.util Projects

java.util Project 1

SortedMap Implementation

In this page of the tutorials we are going to implement to the sortedMap interface in our Java application. A SortedMap is sort the entry data in the ascending order, sorted according to the key's natural order, or according to a Comparator provided at SortedMap creation time.

Previous Home Next
  1. Range-view

  2. It is Perform arbitrary range operations on the sorted map.

  3. Endpoints

  4. It is used to Return the first or last key in the sorted map.

  5. Comparator access

  6. It is used to Return the Comparator used to sort the map (if any).

Example


package r4r;
import java.util.*;
public class sortedmaptest {
public static void main(String[] args) {
SortedMap map = new TreeMap();
map.put("1", "one");
map.put("2", "twO");
map.put("3", "tree");




map.put("4", "Four");
map.put("5", "five");
System.out.println("The lowest key value: " + map.firstKey());
System.out.println("The highest key value: " + map.lastKey());
System.out.println("All key value:\n" + map);
System.out.println("The head map:\n" + map.headMap("2"));
System.out.println("The tail map:\n" + map.tailMap("4"));
Iterator itr = map.keySet().iterator();
while (itr.hasNext()) {
Object key = itr.next();
System.out.println("key : " + key + " value :" + map.get(key));
}
}
}

Previous Home Next