Home Tutorial Java Collections Arrays Array joining Java

 
 

Share on Google+Share on Google+
Array joining Java
Posted on: October 22, 2009 at 12:00 AM
Advertisement
How arrays can be joined in java
  • Two arrays can be joined by using the Collection list.
  • Add all the elements of the both arrays into the list1, list2 respectively.
  • Use addAll() method to add list2 into the list1.Now the list2 is joined in to the list1.

Example
import java.util.*;
public class array3 {
    public static void main(String[] args) {
        int ar3[]={33,45,67,87,34,56};
        int ar4[]={5,8,9,22,3,4};
        List list1=new ArrayList();
        List list2=new ArrayList();
         for (int i = 0; i < ar3.length; i++) {
            list1.add(ar3[i]);
        }
   for (int i = 0; i < ar4.length; i++) {
            list2.add(ar4[i]);
        }
        list1.addAll(list2);
        System.out.println(list);           
    }
}

Output>
33, 45, 67, 87, 34, 56, 5, 8, 9, 22, 3, 4
Advertisement

Related Tags for Array joining Java:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 22, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com