public static void main(String[] args) {
String[] str = {"qws", "123", "1", "ss", "1", "ss"};
//计数器
int count = 0;
for (int i = 0; i < str.length; i++) {
for (int j = 1 + i; j < str.length; j++) {
if (str[i].equals(str[j])) {
System.out.println(str[i]);
count++;
}
}
}
if (count == 0) {
System.out.println("无重复元素!");
} else {
System.out.println("有重复元素");
}
}
Java编写一段代码,判断某字符串数组中是否有重复元素
最新推荐文章于 2024-07-10 21:37:49 发布