2 개의 배열 목록이 있습니다. 저는이 둘 사이의 고유 한 가치를 되돌리고 싶습니다. 어떻게 이뤄지나요?루프리스트를 통해 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'과 같은 리터럴은 ** 문자열 리터럴이 아닙니다 ** – QBrute
코드가 컴파일되지 않습니다. 정수를 문자열 (' "10"'vs'10')로 변경하면 잘 작동합니다. – tnw
전체 코드가 포함되지 않아서 죄송합니다. 이 문자열은 내 서블릿에서 전달되며 DAO로 전달됩니다. 코드를 업데이트합니다. – Gee