Answers for "get element in arraylist java"

6

ArrayList E get(int index) method in java

import java.util.ArrayList;
public class ArrayListGetExample
{
   public static void main(String[] args)
   {
      ArrayList<String> al = new ArrayList<String>();
      al.add("lion");
      al.add("tiger");
      al.add("deer");
      al.add("cheetah");
      al.add("elephant");
      al.add("fox");
      al.add("hyenas");
      al.add("jackal");
      System.out.println("Get second element of ArrayList: " + al.get(1));
      System.out.println("Get third element of ArrayList: " + al.get(2));
      System.out.println("Get fifth element of ArrayList: " + al.get(4));
      System.out.println("Get sixth element of ArrayList: " + al.get(5));
   }
}
Posted by: Guest on October-30-2020
1

how to select a element in an arraylist java

import java.util.ArrayList;
import java.util.Arrays;
 
public class ArrayListExample 
{
    public static void main(String[] args) 
    {
        ArrayList<String> list = new ArrayList<>(Arrays.asList("alex", "brian", "charles", "dough"));
         
        String firstName = list.get(0);         //alex
        String secondName = list.get(1);        //brian
         
        System.out.println(firstName);
        System.out.println(secondName);
    }
}
Posted by: Guest on May-18-2020
0

get element in arraylist java

ArrayObject.get(indexOfElement);
Posted by: Guest on March-27-2021

Code answers related to "get element in arraylist java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language