package demo8;
//实体类
public class Test {
private int number;
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
}
package demo8;
import java.util.ArrayList;
import java.util.List;
public class List1 {
public static void main(String[] args) {
//第一个集合
List<Test> list1=new ArrayList<Test>();
Test list1_1=new Test();
list1_1.setNumber(1);
list1.add(list1_1);
Test list1_2=new Test();
list1_2.setNumber(3);
list1.add(list1_2);
Test list1_3=new Test();
list1_3.setNumber(5);
list1.add(list1_3);
Test list1_4=new Test();
list1_4.setNumber(7);
list1.add(list1_4);
Test list1_5=new Test();
list1_5.setNumber(9);
list1.add(list1_5);
//第二个集合
List<Test> list2=new ArrayList<Test>();
Test list2_1=new Test();
list2_1.setNumber(1);
list2.add(list2_1);
Test list2_2=new Test();
list2_2.setNumber(2);
list2.add(list2_2);
Test list2_3=new Test();
list2_3.setNumber(3);
list2.add(list2_3);
Test list2_4=new Test();
list2_4.setNumber(4);
list2.add(list2_4);
Test list2_5=new Test();
list2_5.setNumber(5);
list2.add(list2_5);
for(int i = 0; i < list1.size();i++){
Test temp = list1.get(i);
int value1=temp.getNumber();
for(int j = 0; j < list2.size();j++){
Test temp1 = list2.get(j);
int value2=temp1.getNumber();
if(value1 == value2){
System.out.println("有相同的元素: " +value1);
}
}
}
}
}
package demo8;//实体类public class Test { private int number; public int getNumber() { return number;}public void setNumber(int number) { this.number = number;}}package demo8;import jav...