Answers for "ArrayList E get(int index) method in java"

2

ArrayList set(int index E element) method in java

import java.util.ArrayList;
public class ArrayListSetMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<String> names = new ArrayList<String>(5);
      names.add("vinay");
      names.add("ajay");
      names.add("vijay");
      names.add("bharat");
      names.add("dinesh");
      System.out.println("ArrayList before using set() method: " + names);
      // change vijay name to chandan
      System.out.println("ArrayList after using set() method: ");
      names.set(2, new String("chandan"));
      for(int a = 0; a < 5; a++)
      {
         System.out.println(names.get(a).toString());
      }
   }
}
Posted by: Guest on October-28-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

Code answers related to "ArrayList E get(int index) method in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language