idzik

Java-Kolekcje-HashMapa.java

Jan 27th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. public class HashMapa {
  5.  
  6.     public static void main(String[] args) {
  7.         HashMap<Integer, String> mapa = new HashMap<Integer, String>();
  8.         mapa.put(1, "jeden");
  9.         mapa.put(2, "dwa");
  10.         mapa.put(3, "trzy");
  11.         mapa.put(4, "cztery");
  12.         mapa.put(5, "piec");
  13.         mapa.put(6, "szesc");
  14.         mapa.put(6, "sz");
  15.  
  16.         String lancuch = mapa.get(6);
  17.         System.out.println(lancuch);
  18.         // wyświetlenie wszsytkich elementów mapy
  19.  
  20.         for (Integer key : mapa.keySet()) {
  21.             String value = mapa.get(key);
  22.             System.out.println("Klucz " + key + ", wartość " + value);
  23.         }
  24.  
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment