It is necessary to create arrays ArrayList with the name, like the player's nickname. So I got a nickname in String. String plname = p.getName(); So I tried to use it as an array name.

 ArrayList<Player> plname = new ArrayList<Player>(); 

But here's the problem: he complains that I rename "plname". How to use String plname as an array name?

    1 answer 1

    No, in Java, variables are not declared dynamically. Use HashMap :

     Map<String, List<Player>> players = new HashMap<>(); players.put(plname, new ArrayList<>()); 
    • Thanks for the answer. Useful information for the future (probably), but I found a solution to my problem (which is not in the subject), without touching the player's name. I just created an array with arrays, and the number of arrays in this array is equal to other arrays ... In general, I will not confuse you, the topic has lost its relevance in such a short time, but thanks for the answer. - asdqwertypro