Jordi Martí Gomez Jordi Martí Gomez - 6 months ago 34
Java Question

how i get the 2nd object of a Hashmap

i have this code:

public class Game {
String NO_MOVEMENTS = ChatColor.RED+"You don't have sufficient movements to do that";
public static HashMap<Player,Integer> movements = new HashMap<>();
public void setupMovements(Player player){
public void movementsManager(Player player){
public static HashMap arrowShoow(Player player){

And i need to know the "movements"(int) of the hashmap, how i do get it??
thank you so much!


The Order (of entry) is not preserved in HashMap, unlike ArrayList. And there is no way you can get the so called secondobject in HashMap.

To access all the elements in a HashMap you can look at this answer.

To get the movement of a particular player you can use:

Integer movement = movements.get(yourPlayerObject);