Advertisement
Samuel_Berkat_Hulu

shdf

Jun 22nd, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class HashTable1 here.
  4.  *
  5.  * Samuel Berkat Hulu
  6.  * @version 5.0 Tugas Struktur Data
  7.  */
  8. import java.util.Hashtable;
  9. import java.util.Iterator;
  10.  
  11. public class HashTable1
  12. {
  13.     public static void main(String[] args)
  14.     {
  15.         //Buat Hastale
  16.         Hashtable<Integer, String> hashtable = new Hashtable<>();
  17.        
  18.         hashtable.put(1, "X");
  19.         hashtable.put(2, "Y");
  20.         hashtable.put(3, "Z");
  21.    
  22.         System.out.println(hashtable);
  23.        
  24.         String value = hashtable.get(1);
  25.         System.out.println(value);
  26.        
  27.         hashtable.remove(3);
  28.        
  29.         Iterator<Integer> itr = hashtable.keySet().iterator();
  30.         while(itr.hasNext())
  31.         {
  32.             Integer key = itr.next();
  33.             String mappedValue = hashtable.get(key);
  34.            
  35.             System.out.println("Kunci : " + key + ", Nilai : " + mappedValue);
  36.         }
  37.        
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement