Currently in my game, if I want to find a player by their unique id I do something like this:
public Player getPlayerByID (int id) {
for (Player player : playerList) {
if (player.getId() == id)
return player;
}
return null;
}
Would using a java HashMap be faster for indexing a player? Using something like this:
HashMap<Integer, Player> playerMap = new HashMap<Integer, Player>();
//Some method to fill hash map with players...
//Get player method
public Player getPlayerByID (int id) {
playerMap.get(id);
}