How to Merge Two Array in JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Tuesday, April 28, 2020

How to Merge Two Array in JAVA

Write a program to merge( two) Array.
public class MergeArray {
    public static void main(String[] args) {

        int array1[]={5,6,7};
        int array2[]={8,9,10,11};

        int array1_length=array1.length;
        int array2_length=array2.length;
        int add=array1_length+array2_length;

        int sum[]=new int[add];

        for (int i=0;i<array1_length;i++)
        {
            sum[i]=array1[i];
        }
        for (int i=0;i<array2_length;i++)
        {
            sum[array1.length+i]=array2[i];
        }
        for (int i=0;i<sum.length;i++){
            System.out.print(sum[i]+" ");
        }
    }
}


Array List and Array Class in Collection



Sorting and Searching Programs
Start with your Choice
-Important Programs for Freshers
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!
Learn with us | HTML | CSS | JS | Bootstrap | JAVA | ADV JAVA | MySQL | GIT


1 comment:

daliahzahrt said...

Luckyland Hotel & Casino - Mapyro
The 안성 출장안마 Luckyland Hotel & Casino 안산 출장마사지 is located in the picturesque 전라남도 출장마사지 East Coast and provides a 용인 출장안마 casino and entertainment venue. The casino 서산 출장마사지 is owned by Sycuan Tribe of Indians

Pages