Write a Java program to remove the third element from a array list


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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.*;
  2. public class Javacollectionexcercise {
  3. public static void main(String[] args) {
  4.  
  5. List<String> listStrings = new ArrayList<String>();
  6. listStrings.add("Audi");
  7. listStrings.add("BMW");
  8. listStrings.add("Bugatti");
  9. listStrings.add("Ford");
  10. listStrings.add("Honda");
  11. listStrings.add("Hyundai");
  12.  
  13. System.out.println(listStrings);
  14. // Removing the third element from the list.
  15. listStrings.remove(2);
  16.  
  17. System.out.println("After removing third element from the list:\n"+listStrings);
  18. }

Result

java techstudy.org

     





Related Topics




Popular Posts