I'm trying to create a mapping in which a UUID key points to both an object (e.g. some User class instance) and auxiliary information about that object (e.g. an int and a String). There are two obvious implementations of this:
import java.util.Map;
import java.util.HashMap;
import java.util.UUID;
...
Map<UUID, User> main = new HashMap<UUID, User>();
Map<UUID, Integer> aux1 = new HashMap<UUID, Integer>();
Map<UUID, String> aux2 = new HashMap<UUID, String>();
or
import java.util.Map;
import java.util.HashMap;
import java.util.UUID;
...
private static class UserInfo { // Nested class
public final User user;
public final int aux1;
public final String aux2;
public UserInfo(User user, int aux1, String aux2) {
this.user = user;
this.aux1 = aux1;
this.aux2 = aux2;
}
}
...
Map<UUID, UserInfo> main = new HashMap<UUID, UserInfo>();
Which is generally considered more performant, in terms of efficiency and memory usage? Or is there a more worthwhile third option?