java compare two arrays code example
Example 1: compare arrays java
import java.util.Arrays;
class Test
{
public static void main (String[] args)
{
int inarr1[] = {1, 2, 3};
int inarr2[] = {1, 2, 3};
Object[] arr1 = {inarr1};
Object[] arr2 = {inarr2};
if (Arrays.equals(arr1, arr2))
System.out.println("Same");
else
System.out.println("Not same");
}
}
Example 2: how to compare elements in an array
for (let i = 0; i < a.length; i++) {
for (let k = i + 1; k < a.length; k++) {
if (a[i] != a[k]) {
}
}
}