Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java treemap

import java.util.*;

// Declare the variable using the interface of the object for flexibility.
// Non-primative data types only.
Map<Integer, String> mambo = new TreeMap<Integer, String>();

mambo.put(key, value);
// TreeMap will be sorted by key.
// Work with any comparable object as a key.

mambo.put(1, "Monica");
mambo.put(2, "Erica");
mambo.put(3, "Rita");
Comment

Implementation of TreeMap Class in Java map

// Java Program to Illustrate TreeMap Class

// Importing required classes
import java.util.*;

// Main class
public class Main {

	// Main driver method
	public static void main(String[] args)
	{

		// Creating an empty TreeMap
		Map<String, Integer> hashmap = new TreeMap<>();

		// Inserting entries in the Map
		// using put() method
		hashmap.put("Banana", 100);
		hashmap.put("Orange", 200);
		hashmap.put("Mango", 300);
		hashmap.put("Apple", 400);
		
		// Iterating over Map using for each loop
		for (Map.Entry<String, Integer> e : hashmap.entrySet())

			// Printing key-value pairs
			System.out.println(e.getKey() + " "+ e.getValue());
	}
}
Comment

Java treemap

import java.util.*;  
class Tree_Map{  
public static void main(String args[]){  
   TreeMap<Integer,String> map=new TreeMap<Integer,String>();    
      map.put(93,"Afghanistan");    
      map.put(213,"Algeria");    
      map.put(55,"Brazil");       
        
      for(Map.Entry mapTree:map.entrySet()){    
       System.out.println(mapTree.getKey()+" "+mapTree.getValue());    
      }    
}  
}
Comment

PREVIOUS NEXT
Code Example
Java :: java determine number of cpu cores 
Java :: iterative inorder traversal 
Java :: java synchronized method 
Java :: how to generate random large string in java 
Java :: how to make a button disapear on click in javafx 
Java :: foreach skip to next java 
Java :: javafx get actionevent id 
Java :: java.lang.double cannot be cast to java.lang.float 
Java :: JFrame change outline 
Java :: Implement the static keyword – static variable, static block, static function and static class with following conditions 
Java :: spring boot api key authentication example 
Java :: android get app build name 
Java :: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
Java :: java string 
Java :: why static variables cannot be serialized in java 
Java :: miles to km converter programm in java 
Java :: java hashmap increase value by 1 
Java :: how to get string value in java in android 
Java :: java wrapper classes 
Java :: stringbuilder java setlength 
Java :: get current location android 
Java :: fragment call activity 
Java :: resttemplate get rest api call in java 
Java :: what does setFocusable do in java 
Java :: capture console output java 
Java :: int arr = new int 
Java :: switch statement in java 
Java :: java append to array 
Java :: java hashmap 
Java :: java 8 lambda comparator 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =