Solved Calling An ArrayList From a Different Class

Discussion in 'Plugin Development' started by acosta9898, May 20, 2014.

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


    So recently I've been programming a hub plugin for my server and I added a hub pvp mode. So I created an ArrayList to store players that are in pvp mode, however, I cant seem to find a way to call the Arraylist from the class that it was made into a different class. I was watching some youtube videos and saw some information about Super classes and stuff however I still don't quite understand them and I don't know if they are even a solution to this problem...

    If anyone has any information on this, it will be very helpful!
  2. Offline


    if the arraylist is static, (in this case, it should be), make it public, and ClassName.arrayListName.methodName, in the other class
  3. Offline


    There are lots of ways to do this.
    One way would be to use static:

    1. public class A {
    2. public static ArrayList<String> array = new ArrayList<String>();
    3. }
    5. public class B {
    6. private void dosomething () {
    7. int size = A.array.size(); //Example to find the size of the array that is in another class
    8. }
    9. }
  4. Offline


    Sabersamus So it should look like this?:

    1. public static List<Player> canDoPvP = new ArrayList<Player>();

    and what do you mean by methodName?

    srry im a little new to Java and the Bukkit API :p


    LOL disregard that ^ I understand what u meant now Sabersamus !

    @CraftedShack Oh.. Ok Thank You!! That clears it up!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 8, 2016
  5. Offline


    methodName = the name of the method you are calling.

    Such as List#add()
  6. Offline


Thread Status:
Not open for further replies.

Share This Page