For combining or joining two ArrayList will be using addAll() method
Eg:
Eg:
public static void main(String[]args){
//creation of Arraylist 1 with string arguments
//adding elements to Arraylist 1
ArrayList<String> al=new ArrayList<String>();
al.add("India");
al.add("US");
//Displaying elements of Arraylist
System.out.println(al);
//creation of Arraylist 2 with string arguments
ArrayList<String> al=new ArrayList<String>();
/adding elements to Arraylist 2
al2.add("Australia");
al2.add("Germany");
al2.add("Europe");
al.addAll(al2);
al.addAll(al2);
}
Output:[India,US,Australia,Germany,Europe]
Nice post!!
ReplyDelete