Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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());
	}
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Implementation #TreeMap #Class #Java #map
ADD COMMENT
Topic
Name
2+2 =