“Java Treemap” Code-Antworten

Implementierung der Treemap -Klasse in Java -Karte

// 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());
	}
}
Outrageous Ostrich

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());    
      }    
}  
}
Unsightly Unicorn

Ähnliche Antworten wie “Java Treemap”

Fragen ähnlich wie “Java Treemap”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen