I have two classes:
public class Cat
{
public Cat(UUID id, String name)
{
this.id = id;
this.name = name;
}
@Getter
UUID id;
@Getter
String name;
}
public class Animal
{
@Getter
UUID id;
@Getter
String name;
}
And I have two maps:
Map<Cat, Location> map = new HashMap<>();
Map<Animal, Location> map2 = new HashMap<>();
I need to easily convert map2
data into a map
. I was able to do it with the following code:
for (Entry<Animal, Location> entry : map2.entrySet())
{
UUID id = entry.getKey().getId();
String name = entry.getKey().getName();
Cat key = new Cat(id, name);
map.put(key, entry.getValue());
}
return map;
Is there a better way to do this or is the approach I'm taking ok?