Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Creating Hashmap from Treemap

import java.util.HashMap;
import java.util.TreeMap;

class Main {
  public static void main(String[] args) {

    // create a treemap
    TreeMap<String, Integer> map = new TreeMap<>();
    map.put("Dog",1);
    map.put("Wolf",2);
    System.out.println("TreeMap: " + map+"
");

    // create hashmap from the treemap
    HashMap<String, Integer> map1 = new HashMap<>(map);
    map1.put("Leopard",3);
    System.out.println("HashMap: " + map1);
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Creating #Hashmap #Treemap
ADD COMMENT
Topic
Name
6+4 =