ArrayList add problem

Discussion in 'Plugin Development' started by ThrustLP, Mar 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ThrustLP

    Hello! My little problem is that my ArrayList is a Player ArrayList:
    Code:java
    1. ArrayList<Player> players = new ArrayList<Player>();


    How can I add players to it?
    Code:java
    1. players.add(p.getName());

    doesn't work!
     
  2. Offline

    HenoLima

    If you use .getName() it returns a string , so change in the declaration of your array list :
    Code:java
    1. ArrayList<String> players = new ArrayList<String>();

    And it should work :)
     
  3. Offline

    ThrustLP

    HenoLima
    Thank you :)
    But I use Player because I have got this part of code:
    Code:java
    1. Player playerOne = players.get(0);


    And it doesn't work with "String", does ist?
     
  4. ThrustLP
    Code:java
    1. // Array
    2. ArrayList<String> players = new ArrayList<String>();
    3.  
    4. // Adding values
    5. players.add(p.getName());
    6.  
    7. // Getting players
    8. Player player = Bukkit.getPlayerExact(players.get(0));
    9.  


    Just fyi, player can be null
     
    Konkz likes this.
Thread Status:
Not open for further replies.

Share This Page