Solved Arraylist

Discussion in 'Spigot Plugin Development' started by patricianko, May 30, 2018.

  1. Hi! I need help with arraylist when i want to get index trought string.


    [0] Milk
    [1] Melon
    [2] Steak

    method, getIndex(ArrayList<String>, String)
    when i call it getIndex(lines, "Steak") i get return 2.

    Thanks for some code solutions!
  2. Use a for loop and Start like this

    for(int i = 0; i < list.size(); i++) {
    //Do Something
    • Like Like x 1
  3. arrayList.indexOf("string") ?
    • Like Like x 1
    • Agree Agree x 1
  4. Not sure if there is a method to find something out of the arraylist based on its values but what I'd do if there weren't one is:

    Code (Java):

    List<String> exampleList = new ArrayList<String>(Arrays.asList("steak", "milk", "melon"));

    int getSeat(String item) {
    int count = 0;
    for (String loop : exampleList) {
        if (item.equals(loop)) {
               return count;        
    return -1;
    So basically if I were to use getSeat("milk") it would return 1.
    If I were to use getSeat("steak") it would return 0

    It's pretty basic and quite self explanatory... you get the idea.
    • Friendly Friendly x 1
  5. Mas


    You literally got handed a much more elegant solution in the second response and ignored it. Not to mention the fact you couldn't be bothered to search this yourself so relied on others to spoonfeed it to you.
    • Agree Agree x 3