法1 循环遍历
public class Test0406(){
public static void main(String[] args){
String[] arr = {"草莓","苹果","猕猴桃","橘子","火龙果","苹果","猕猴桃"};
isRepeat(arr);
}
public static void isRepeat(String[] arr){
for(int i = 0; i < arr.length-1; i++){
for(int j = i+1 ; j < arr.length;){
if(arr[i] == arr[j]){
System.out.println("有重复值:"+arr[j]);
break;
}else{
j++;
}
}
}
}
}
打印结果为
有重复值:苹果
有重复值:猕猴桃
<!2022不变秃只变强!>