Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to compare the contents of integer arrays in java?
How to compare the contents of integer arrays in java?
I am very reliable. Just try it.

Public class Arrcom {

Static intnum = 0;

Public static void main(String[] args){

int[] a={3,0, 1 };

int[] b={ 1,6,0 };

int[] ab=com(a,b); //comparison

my print(ab); //print

}

//Here, the same elements in two arrays are output in reverse order according to the time they were stored in the arrays. Just output it in the way you want.

Static void myPrint(int[] arr){

for(int I = num- 1; I & gt=0; I-) {

system . out . print(arr[I]+" ");

}

}

//Once the same value is stored in the array ab.

Static int[] com(int[] a, int[] b){

If (a.length & gtB.length){// prevents ab from being saved.

int[]ab = new int[a . length];

for(int I = 0; I<a. Length; i++){

for(int j = 0; J<b. Length; j++){

if(a[i]==b[j]){

ab[num]= a[I]; //Once A and B store the same value in ab, A, B and ab are all arrays.

num++;

}

}

}

Return to ab; //Returns the array ab, the same below.

} Otherwise {

int[]ab = new int[b . length];

for(int I = 0; I<a. Length; i++){

for(int j = 0; J<b. Length; j++){

if(a[i]==b[j]){

ab[num]= a[I];

num++;

}

}

}

Return to ab;

}

}

}