Method for getting array list?

Discussion in 'Plugin Development' started by danielh112, Jan 18, 2014.

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

    danielh112

    Hi I have been trying to return an array list using
    Code:java
    1. public ArrayList<Player> getArena(String getArena) {
    2. if(getArena.equals(Arena1)) {
    3. return Arena1;
    4. }
    5. if(getArena.equals(Arena2)) {
    6. return Arena2;
    7. }
    8. return null;
    9. }

    but i cannot get it to work/access it from another method and I am not sure why I know I am being really stupid but I have not tried these before but if someone could tell me that would be great!
    Thank you for your help/patience!
     
  2. Offline

    SacredWaste

    First off, never ever have any array lists or hash maps with Player. Second, for an array (not a hash map), you'd loop through the array checking if a value, in this case, a name, is equal to getArena.
     
  3. Offline

    danielh112

    Ok thank you for letting me know about not storing it as players. But also I should have said Arena1 and Arena2 are the names of different array lists I am using. So I was wondering how I can return the actual array list rather than a value inside
    Thank you for that! I apalogise if I annoyed about storing them as players :)
     
  4. Offline

    SacredWaste

    danielh112 Storing player's is just bad practice, and can lead to many memory leaks. As for array's, try the Arrays.toString() method. It will print as an array, with some brackets (or something similar) I believe, but can easily be removed.
     
Thread Status:
Not open for further replies.

Share This Page