The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java : Collection Framework : ArrayList (Add Group of Objects)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java : Collection Framework : ArrayList (Add Group of Objects) Posted: Oct 1, 2014 11:27 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java : Collection Framework : ArrayList (Add Group of Objects)
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement























Click here to watch in Youtube : https://www.youtube.com/watch?v=xlXzkTrsO44

ArrayListAddAllListExample.java
import java.util.ArrayList;

/*
* Example of addAll(Collection<? extends E> c) method
*/

public class ArrayListAddAllListExample
{

public static void main(String[] args)
{
ArrayList<String> arrayList1 = new ArrayList<String>();
arrayList1.add("Ram");
arrayList1.add("Dave");
arrayList1.add("Peter");

System.out.println("arrayList 1 : " + arrayList1);

ArrayList<String> ArrayList2 = new ArrayList<String>();
ArrayList2.add("Julia");
ArrayList2.add("Akram");

System.out.println("ArrayList 2 : " + ArrayList2);

/*
* Adding ArrayList2 collection elements to the arrayList1 collection
*/


arrayList1.addAll(ArrayList2);

System.out
.println("After adding ArrayList2 collection elements to the arrayList1 collection ");

System.out.println("arrayList 1 : " + arrayList1);

}

}

Output
arrayList 1 : [Ram, Dave, Peter]
ArrayList 2 : [Julia, Akram]
After adding ArrayList2 collection elements to the arrayList1 collection
arrayList 1 : [Ram, Dave, Peter, Julia, Akram]

ArrayListAddAllSetExample.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/*
* Example of addAll(Collection<? extends E> c) method
*/

public class ArrayListAddAllSetExample
{

public static void main(String[] args)
{
List<String> list = new ArrayList<String>();
list.add("Ram");
list.add("Dave");
list.add("Peter");

System.out.println("List : " + list);

Set<String> set = new HashSet<String>();
set.add("Julia");
set.add("Akram");

System.out.println("Set : " + set);

/*
* Adding Set collection elements to the list collection
*/


list.addAll(set);

System.out.println("List : " + list);

}

}

Output
List : [Ram, Dave, Peter]
Set : [Julia, Akram]
List : [Ram, Dave, Peter, Julia, Akram]

To Download ArrayListDemoAddAll Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoAddAll.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Read: Java : Collection Framework : ArrayList (Add Group of Objects)

    Topic: log4j rootlogger example Previous Topic   Next Topic Topic: Embedded Jetty and Apache CXF: secure REST services with Spring Security

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use