Advertisement
mbah_bejo

Hash Map Contoh

Oct 25th, 2020
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. /**
  5.  * Collection dengan
  6.  * Hash map
  7.  *
  8.  * @author Thomasdwi.a
  9.  * @version 20201025
  10.  */
  11. public class hashMapContoh {
  12.     public static void main (String [] args){
  13.  
  14.         HashMap<Integer, String> hm = new HashMap<Integer, String>();
  15.         hm.put(101,"anwar");
  16.         hm.put(102,"Amir");
  17.         hm.put(103,"Amos");
  18.         hm.put(null,"Zo");
  19.  
  20.         for (Map.Entry m : hm.entrySet()) {
  21.             System.out.println(m.getKey()+" "+m.getValue());
  22.         }
  23.     }
  24. }
  25. /** Output:
  26.  * null Zo
  27.  * 101 anwar
  28.  * 102 Amir
  29.  * 103 Amos
  30.  */
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement