Answers for "how to get the index of a value in list in java"

0

how to get the index of a value in list in java

import java.util.ArrayList;

public class ArrayListDemo {
   public static void main(String[] args) {
      ArrayList<String> arrlist = new ArrayList<String>(5);
      arrlist.add("G");
      arrlist.add("E");
      arrlist.add("F");
      arrlist.add("M");
      System.out.println("Size of list: " + arrlist.size());
      for (String value : arrlist) {
         System.out.println("Value = " + value);
      }
      int retval=arrlist.indexOf("E");
      System.out.println("The element E is at index " + retval);
   }
}
Posted by: Guest on July-15-2021

Code answers related to "how to get the index of a value in list in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language