naufalphew

Hashmap

Oct 26th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1.  import java.util.*;
  2.  class HashMapContoh{
  3.      public static void main(String args[]){
  4.          //membuat hashmap
  5.          HashMap<Integer,String> hm=new HashMap<Integer,String>();
  6.          //input objek
  7.          hm.put(100,"Kano");
  8.          hm.put(101,"Laila");
  9.          hm.put(102,"Badu");
  10.          hm.put(null, "Johan");
  11.          //menampilkan isi
  12.          for(Map.Entry m:hm.entrySet()) {
  13.              System.out.println(m.getKey()+" "+m.getValue());
  14.          }
  15.      }
  16.  }
Advertisement
Add Comment
Please, Sign In to add comment