Friday 25 March 2016

Array appending

Code:


class append {

     public static void main(String []args) {

        int[] a = new int[] { 1, 2, 3};
        int[] b = new int[] { 3, 4, 5};
        int[] r = new int[a.length + b.length];
        System.arraycopy(a, 0, r, 0, a.length);
        System.arraycopy(b, 0, r, a.length, b.length);
        for(int x : r) {
            System.out.println(x);
        }           
     }        
}


Output:

 

No comments:

Post a Comment