3:53 pm - Monday March 25, 1078

How to Add Multiple Objects to an Arraylist

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 Following method is used to add All object to ArrayList from other Collection Objects.

Example Program

import java.util.ArrayList;

public class Fun
{

public static void main(String[] args)

{

ArrayList Student=new ArrayList();

Student.add("name:");

Student.add("age:");

Student.add("email:");

System.out.println("Enter the details");

for (String Name:Student)

{

System.out.println(Name);

}

ArrayList Student1=new ArrayList();

Student1.add("date of birth:");

Student1.add("id:");

Student1.add("college name:");

Student1.add("verification code:");

System.out.println("Enter the student verification details");

for (String Name:Student1)

{

System.out.println(Name);

}

Student.addAll(Student1);

System.out.println("\n"+"Print all the details:"+" "+"\n");

for (String s1 : Student)
{

System.out.println(s1);

}
}
}

Output

   Enter the details

   name:

   age:

   email:

   Enter the student verification details

   date of birth:

   id:

   college name:

   verification code:

   Print all the details:

   name:

   age:

   email:

   date of birth:

   id:

   college name:

   verification code:

BACK

Filed in: Java Examples

Comments are closed.