Write a Java program to increase the size of an array list

Write a Java program to increase the size of an 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

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. public class Javacollectionexcercise {
  4. public static void main(String[] args) {
  5. ArrayList<String> Stringslist= new ArrayList<String>(3);
  6. Stringslist.add("Audi");
  7. Stringslist.add("BMW");
  8. Stringslist.add("Bugatti");
  9. System.out.println("Original array list: " + Stringslist);
  10. //Increase capacity to 7
  11. Stringslist.ensureCapacity(7);
  12. Stringslist.add("Ford");
  13. Stringslist.add("Honda");
  14. Stringslist.add("Hyundai");
  15. Stringslist.add("Ferrari");
  16. System.out.println("New Increased array list: " + Stringslist);
  17. }
  18. }

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.