I have a ArrayList
of class, when loading it in the following way:
ArrayList<Diccionario> puertaHabitacion= new ArrayList<Diccionario>();
Diccionario puertaHab=new Diccionario();
puertaHab.setClave("Puerta Cocina");
puertaHab.setValor("Cocina");
puertaHabitacion.add(puertaHab);
puertaHab.setClave("Puerta Estudio");
puertaHab.setValor("Estudio");
puertaHabitacion.add(puertaHab);
puertaHab.setClave("Puerta Baño");
puertaHab.setValor("Baño");
puertaHabitacion.add(puertaHab);
puertaHab.setClave("Puerta Principal");
puertaHab.setValor("Principal");
puertaHabitacion.add(puertaHab);
In this particular example and entered 4 objects of type Dictionary in ArrayList
however when printing the ArrayList
complete the last entered values are repeated, that is to say in all the values I get as keys "Main Door" and as "Main" values
Because this error occurs and how I can solve this problem