public static void main(String[] args) {
String s[]={"1","2","3","4"};
List<String> k = new ArrayList<String>();
k.add("1");
k.add("2");
k.add("3");
k.add("4");
k.add("5");
k.add("6");
for (String ss : k) {
for (String d : s) {
if(d.equals(ss)){
System.out.println("相同:"+ss);
}else{
System.out.println("不相同:"+ss);
}
}
}
}
不好意思,剛才沒看仔細,這下應該好了
import java.util.*;
public class test{
public static void main(String[] args) {
String s[]={"1","2","3","4"};
int flag=0;
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
list.add("3");
list.add("4");
list.add("5");
list.add("6");
for (String l: list) {
for (String str:s) {
if(s.equals(l)){
System.out.println("相同:"+str);
flag=1;
break;
}
else {
flag=0;
}
}
if (flag==0) {
System.out.println("不相同:"+l);
}
}
}
}