java - how i get the 2nd object of a Hashmap -


i have code:

public class game {     string no_movements = chatcolor.red+"you don't have sufficient movements that";     public static hashmap<player,integer> movements = new hashmap<>();     public void setupmovements(player player){         movements.put(player,15);     }     public void movementsmanager(player player){     }     public static hashmap arrowshoow(player player){     } } 

and need know "movements"(int) of hashmap, how it?? thank much!

if want know integer value specified player:

integer value = movements.get(player); 

if want know player specified integer:

integer value = 15; /* put int value looking here */ player player = movements.entryset().stream()         .filter(entry -> entry.getvalue().equals(value)); 

keep in mind if there no player specific integer, null.

if want second object inserted map, need use linkedhashmap, retains order in keys inserted map. retrieve second item inserted map:

player player = movements.keyset().get(1); 

note: assumes there @ least 2 items in map. can change if remove item map (because if remove first item map, second item become first).


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -