gpt4 book ai didi

java - 如何在Java中检查字符串数组中的相同名称?

转载 作者:行者123 更新时间:2023-12-02 05:57:37 24 4
gpt4 key购买 nike

我有一个名称数组 (temp3)。

我需要确定数组中的任何名称是否等于另一个名称,而不需要重复比较。

这就是我到目前为止所拥有的,谢谢。

for(int m=0; m<3; m++){
for(int n=0; n<3; n++){
if(m!=n){
if(temp3[m]==temp3[n]){
System.out.println("Yes");
}
}
}
}

最佳答案

for(int i=0; i< strings.length;i++){        // Pick a string
for(int j=i+1; j<strings.length;j++){ // Loop on all strings starting from i+1
if(strings[i].equals(strings[j])) // check if the two strings are equal
System.out.println("The two strings are the same"); // SOP
}
}
}

关于java - 如何在Java中检查字符串数组中的相同名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22949576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com