Write a Java program to insert an element into the array list at the first position

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

import java.util.*;
  public class Javacollectionexcercise {
  public static void main(String[] args) {
  List<String> Stringslist = new ArrayList<String>();
  Stringslist.add("Audi");
  Stringslist.add("BMW");    
  Stringslist.add("Bugatti");
  Stringslist.add("Ford");
  Stringslist.add("Honda");
  Stringslist.add("Hyundai");
 
  System.out.println(Stringslist);
 
  Stringslist.add(0, "Ferrari");
  Stringslist.add(7, "Fiat");
 
  System.out.println(Stringslist);
 }
}

Result

Write a Java program to insert an element into the array list at the first position
Write a Java program to insert an element into the array list at the first position

Leave a Comment