- package com.hoocy;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- public class TestUserC {
- public static void main(String[] args) {
- List list = new ArrayList<User>();
- List<User> ListA = new ArrayList<User>();
- List<User> ListB = new ArrayList<User>();
- init(ListA, ListB);
- if (ListA != null) {
- Iterator it = ListA.iterator();
- while (it.hasNext()) {
- list.add((User) it.next());
- }
- }
- if (ListB != null) {
- Iterator it = ListB.iterator();
- while (it.hasNext()) {
- User o = (User) it.next();
- if (!list.contains(o))
- list.add(o);
- }
- }
- for (int i = 0; i < list.size(); i++) {
- System.out.println(((User)list.get(i)).getName());
- }
- }
- public static void init(List list,List list2){
- User user1 = new User("hoocy1","d","");
- User user2 = new User("hoocy2","d","");
- User user3 = new User("hoocy3","d","");
- User user4 = new User("hoocy4","d","");
- User user5 = new User("hoocy5","d","");
- list.add(user1);
- list.add(user2);
- list.add(user3);
- list.add(user4);
- list.add(user5);
- User user6 = new User("hoocy1","d","");
- User user7 = new User("hoocy2","d","");
- User user8 = new User("hoocy3","d","");
- User user9 = new User("hoocy88","d","");
- User user10 = new User("hoocy55","d","");
- list2.add(user10);
- list2.add(user6);
- list2.add(user7);
- list2.add(user8);
- list2.add(user9);
- }
- }
- 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
- package com.hoocy;
- public class User {
- private String name;
- private String type;
- private String date;
- User(){}
- User(String name,String type,String date)
- {
- this.name=name;
- this.type=type;
- this.date=date;
- }
- public String getDate() {
- return date;
- }
- public void setDate(String date) {
- this.date = date;
- }
- public String getName() {
- return name==null?"null":name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getType() {
- return type;
- }
- public void setType(String type) {
- this.type = type;
- }
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- final User other = (User) obj;
- if(this.getName()!=other.getName())
- return false;
- return true;
- }
- }
- 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
-
结果
hoocy1
google_protectAndRun("render_ads.js::google_render_ad", google_handleError, google_render_ad);
hoocy2
hoocy3
hoocy4
hoocy5
hoocy55
hoocy88