Write a Java program to join two array lists

Write a Java program to join two array lists


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> Stringslist1= new ArrayList<String>();
  6. Stringslist1.add("Audi");
  7. Stringslist1.add("BMW");
  8. Stringslist1.add("Bugatti");
  9. Stringslist1.add("Ford");
  10. Stringslist1.add("Honda");
  11.  
  12. System.out.println("First array list: " + Stringslist1);
  13. ArrayList<String> Stringslist2= new ArrayList<String>();
  14. Stringslist2.add("Ferrari");
  15. Stringslist2.add("Fiat");
  16. Stringslist2.add("Honda");
  17. Stringslist2.add("Hyundai");
  18. System.out.println("Second array list: " + Stringslist2);
  19.  
  20. // Let join above two list
  21. ArrayList<String> a = new ArrayList<String>();
  22. a.addAll(Stringslist1);
  23. a.addAll(Stringslist2);
  24. System.out.println("New array list: " + a);
  25.  
  26.  
  27. }
  28. }

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