TreeMap with Duplicate Keys





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.Comparator;
import java.util.TreeMap;

public class TreeMapFlight {

  public static void main(String[] bag){
  TreeMap<Integer,String> tm = new TreeMap<Integer,String>(new MyComp());
  tm.put(1, "one");
  tm.put(1, "null1");
  tm.put(1, "null2");
  tm.put(1, "null3");
 
  System.out.println(tm);  
 }
}

class MyComp implements Comparator{
 @Override
 public int compare(Object o1, Object o2) {
  return 1;
 } 
}
OUTPUT
{1=one, 1=null1, 1=null2, 1=null3}

Popular posts from this blog

PassByValue Test

Condition Test and TreeMap

TreeMap Test