【发布时间】:2017-07-29 10:51:07
【问题描述】:
我有 2 个数组列表。我想返回两者之间的唯一值。这是怎么做到的?
String[] s1 = {10, 1};
String[] s2 = {10, 1, 13};
//loop through and compare element of s1 to s2
//switch varialbe used to indicate whether a match was found
boolean matchFound = false;
//outer loop for all the elements in s2
for (int i = 0; i < s2.lenght; i++) {
//inner loop for all the elements in s1
for (int i = 0; i < s1.lenght; i++) {
matchFound = true;
System.out.println("This " + s2[i] + "was found");
}
}
if(matchFound == false) {
System.out.println("This " + s2[i] + "was not found");
}
//set matchFound bool back to false
matchFound = false;
}
【问题讨论】:
-
像
10和1这样的文字不是String文字 -
您的代码无法编译。如果您将整数更改为字符串(
"10"与10),则效果很好。 -
很抱歉我没有包含整个代码。这些字符串从我的 servlet 传递,我将它传递给 DAO。我更新了我的代码。