Write a Java program to create a new array list, add some elements (string) and print out the collection


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. List<String> listStrings = new ArrayList<String>();
  5. listStrings.add("Audi");
  6. listStrings.add("BMW");
  7. listStrings.add("Bugatti");
  8. listStrings.add("Ford");
  9. listStrings.add("Honda");
  10. listStrings.add("Hyundai");
  11. System.out.println(listStrings);
  12. }
  13. }

Result

java techstudy.org

     





Related Topics




Popular Posts