Java SortedMap create synchronized SortedMap from NavigableMap

Description

Java SortedMap create synchronized SortedMap from NavigableMap

import java.util.Collections;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {
  public static void main(String[] args) {
    NavigableMap<Integer, String> map = new TreeMap<Integer, String>();
    map.put(1, "CSS");
    map.put(2, "HTML");
    map.put(3, "Java");
    map.put(4, "Javascript");
    map.put(5, "SQL");

    System.out.println(map.getClass());
    // wrap into synchronized SortedMap
    SortedMap<Integer, String> ssmap = Collections.synchronizedSortedMap(map);
    /*w w  w .  j av  a  2  s  .  c om*/
    System.out.println(ssmap.getClass());
    
  }
}



PreviousNext

Related