I have a class Player
public Player (String name, int num) {
name = name;
num= num;
}
//getters and Setters
then I will have a list of players
List<Player> listPlayers = new ArrayList<Player>();
I need to make a method to return the player name given the number
String getPlayerName(int num){
...
}
I can make the method seeing all the list but I want to do this in a more efficient way.
Can someone give me some tips?
Thanks for the help.
Use a
Map<Integer, Player>to store all players. Fetching a player from a map by hisnumwill be very efficent: