工具(筛选掉类中相同属性值的记录)

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.travelsky.htlcrslogic.channel.model.Channel;

public class ChannelUtil {
public static List channel2Pseudocitycode(List list){
List newList=new ArrayList();
Set set=new HashSet();
for(int j=0;list!=null&&j Channel c=(Channel)list.get(j);
if(!set.contains(c.getPseudocityCode())){
set.add(c.getPseudocityCode());
newList.add(c);
}

}
return newList;

}
public static void main(String[] args) {
Channel c=new Channel();
c.setPseudocityCode("xx");
c.setChannelCode("yy0");
c.setUrl("11");

Channel c1=new Channel();
c1.setPseudocityCode("xx1");
c1.setChannelCode("yy1");
c1.setUrl("111");

Channel c2=new Channel();
c2.setPseudocityCode("xx");
c2.setChannelCode("yy2");
c2.setUrl("11");

Channel c3=new Channel();
c3.setPseudocityCode("xx2");
c3.setChannelCode("yy3");
c3.setUrl("112");
List l=new ArrayList();
l.add(c);
l.add(c1);
l.add(c2);
l.add(c3);

List x=channel2Pseudocitycode(l);
System.out.println(x.size());
System.out.println("xx");
}
}

你可能感兴趣的:(工具(筛选掉类中相同属性值的记录))