两个List循环
package execise;
import java.util.ArrayList;
import java.util.List;
import domain.User;
public class MainTest {
/**
* @param args
*/
public static void main(String[] args) {
User user=new User();
user.setId(1);
user.setName("aa");
user.setSex("man");
User user1=new User();
user1.setId(2);
user1.setName("bb");
user1.setSex("woman");
List<User> list=new ArrayList<User>();
list.add(user);
list.add(user1);
List<User> list1=new ArrayList<User>();
list1.add(user);
list1.add(user1);
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < list1.size(); j++) {
if(list.get(i).getName().equals(list1.get(j).getName())){
System.out.println(list.get(i).getSex()+list1.get(j).getSex());
System.out.println("--"+list.get(i).getSex()+list1.get(j).getSex());
}
}
}
}
}
package domain;
/**
* @author twc
*
*/
public class User {
private int id;
private String name;
private String sex;
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
显示出
manman
--manman
womanwoman
--womanwoman
欢迎关注公众号:Java后端技术全栈