Answers for "map.put"

10

map java

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


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

      //La fameuse syntaxe en diamant de Java 7
      Map<Integer, String> hm = new HashMap<>();
      hm.put(10, "1");
      hm.put(20, "2");
      hm.put(30, "3");
      hm.put(40, "4");
      hm.put(50, "5");
      //Ceci va écraser la valeur 5
      hm.put(50, "6");
      
      System.out.println("Parcours de l'objet HashMap : ");
      Set<Entry<Integer, String>> setHm = hm.entrySet();
      Iterator<Entry<Integer, String>> it = setHm.iterator();
      while(it.hasNext()){
         Entry<Integer, String> e = it.next();
         System.out.println(e.getKey() + " : " + e.getValue());
      }
      
      System.out.println("Valeur pour la clé 8 : " + hm.get(8));
      
      Map<Integer, String> lhm = new LinkedHashMap<>();
      lhm.put(10, "1");
      lhm.put(20, "2");
      lhm.put(30, "3");
      lhm.put(40, "4");
      lhm.put(50, "5");
      
      System.out.println("Parcours de l'objet LinkedHashMap : ");      
      Set<Entry<Integer, String>> setLhm = lhm.entrySet();
      Iterator<Entry<Integer, String>> it2 = setLhm.iterator();
      while(it2.hasNext()){
         Entry<Integer, String> e = it2.next();
         System.out.println(e.getKey() + " : " + e.getValue());
      }
   }
}
Posted by: Guest on May-10-2020
0

map.put in java

import java.util.*;
public HashMap{
    public static void main(String[] args){
        Map<Integer, String> map = new HashMap<>();//initialization of HashMap 
        map.put(key, value);//key and value must be entered
        System.out.println(map);
    }
}
Posted by: Guest on May-21-2021
1

java add element to map

map.put(key, Object);
//exemple:
Map<String, String> map = new HashMap<String, String>();
map.put("mykey", "myvalue");
Posted by: Guest on July-05-2020
0

Map put() method

Map<String, String> map = new HashMap<String, String>();  // Make an empty map

  map.put("es", "Spain");  // Add the key/value pairs
  map.put("us", "United States");
  map.put("zw", "Zimbabwe");
Posted by: Guest on October-25-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language