Lo que haré lo cual es muy simple, pero la memoria de residuos es mapear los valores con una llave y hacer lo opuesto a mapear las teclas con un valor de hacer esto:
private Map<Object, Object> team1 = new HashMap<Object, Object>();
es importante que utiliza <Object, Object>
para que pueda mapear keys:Value
y Value:Keys
como esto
team1.put("United", 5);
team1.put(5, "United");
tanto, si utiliza team1.get("United") = 5
y team1.get(5) = "United"
Pero si se utiliza algún método específico en una de los objetos en los pares estaré mejor si haces otro mapa:
private Map<String, Integer> team1 = new HashMap<String, Integer>();
private Map<Integer, String> team1Keys = new HashMap<Integer, String>();
y luego
team1.put("United", 5);
team1Keys.put(5, "United");
y recordar, que sea sencillo;)
Un mapa contiene varias claves. Es un diccionario. Tu pregunta no tiene sentido. –
¿Qué espera 'team1.getKey()' para devolver si: (1) el mapa está vacío, o (2) si contiene varias claves? – NPE
'int' se debe utilizar para los únicos como este. –