Demonstration using int[] array here
Copy the code code as follows:
public static void main(String[] args) {
int[] arry={1,10,5,8,11,100,99,10};
//Tag used to determine whether there are duplicate values
boolean flag=false;
for (int i = 0; i < arry.length; i++) {
int temp=arry[i];
int count=0;
for (int j = 0; j < arry.length; j++) {
int temp2=arry[j];
//If there are duplicate values, count+1
if(temp==temp2){
count++;
}
}
//Since it will be compared with itself again in the middle, it must be judged here that count>=2
if(count>=2){
flag=true;
}
}
if(flag){
System.out.println("Duplicate values exist!!!");
}else{
System.out.println("No duplicate values exist!!!");
}
}