Advertisement
gonzalob

Untitled

May 3rd, 2022
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. HashMap<String, Vehiculo> hashMap = new HashMap<>();
  2.         hashMap.put("1ABC", new Vehiculo("1ABC","fiat"));
  3.         hashMap.put("2ABC", new Vehiculo("2ABC","fiat"));
  4.         hashMap.put("3ABC", new Vehiculo("3ABC","mercedes"));
  5.         hashMap.put("2ABC", new Vehiculo("2ABC","ferari"));
  6.        
  7.         Vehiculo vehiculo = hashMap.get("1ABC");
  8.        
  9.         boolean encontrado = hashMap.containsKey("1ABC");
  10.        
  11.         hashMap.remove("2ABC");
  12.        
  13.        
  14.         //diccionario (mapa, clave-valor) -> conjunto (set, corral) -> tabla
  15.         Iterator it = hashMap.entrySet().iterator();
  16.         while (it.hasNext())
  17.         {
  18.             Map.Entry<String, Vehiculo> filaTabla = (Entry<String, Vehiculo>) it.next();
  19.             System.out.println(filaTabla.getKey());//soy la clave
  20.             System.out.println(filaTabla.getValue()); //soy el valor
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement