arraylist help

Discussion in 'Plugin Development' started by 15987632, Aug 10, 2014.

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

    15987632

    so i made an arraylist. What i was planning on doing was shuffling the arraylist and taking the first material of it to pull out a random item from the config. i forgot how to pull out the first material :/

    Code:java
    1. // this is my arraylist
    2. ArrayList<Material> list = (ArrayList<Material>) getConfig().getList("Materials");
    3.  
    4. // this is what im using to shuffle it
    5. Collections.shuffle(list);
    6.  
    7. // i thought this is what i was supposed to do to take the first value from it but i forgot :/
    8. list[0]
     
  2. Offline

    SmooshCakez

    If you did Material[] list; instead of an ArrayList, you would use list[0];. For this, try using list.get(0);. Seems simple enough.
     
  3. Offline

    _Cookie_

    Just a question, why are you using an ArrayList when you're getting a list?..
     
  4. Offline

    15987632

    SmooshCakez thanks :)

    _Cookie_ Im new to this and im kinda doing what i know atm so i didnt know a better way. If you wouldnt mind teaching me that would be great :)
     
  5. Offline

    SmooshCakez

    15987632 I'd usually use this method when getting a list.
    Code:java
    1. Material[] list = getConfig().getList("Materials");

    Using an ArrayList isn't going to harm you, though.
     
  6. Offline

    15987632

Thread Status:
Not open for further replies.

Share This Page