//两个数组中重复的元素 String[] str1={1,55,22,55,41,21,12,8,9}; String[] str2={1,33,23,52,41,22,12,2,5,8}; Arrays.sort(str1); Arrays.sort(str2); if(Arrays.equals(str1, str2)){ System.out.print("重复元素"); } List<String> list=new ArrayList<>(); List<String> list2=new ArrayList<>(); list.addAll(Arrays.asList(str1)); list2.addAll(Arrays.asList(str2); //retainAll 会删除两个数组中不存在的元素 if(list.retainAll(list2)){ System.out.print("重复元素"); } //某个值在数组中是否存在 if(Arrays.asList(str1).contains("1")){ System.out.print("存在元素"); }
?