日期:2014-05-20 浏览次数:20966 次
//删除重复的用户名
Set<String> names = new HashSet<String>();
List<String> sendUserNames = new ArrayList();
for(UserEvent ue : userEventByFeedIdList){
sendUserNames.add(ue.getSendUserName());
}
names.addAll(sendUserNames);
sendUserName = StringUtils.collToStr(names);
Set<String> nameSet = new HashSet<String>();
List<String> list = new ArrayList<String>();
list.add("123");
list.add("456");
list.add("123");
list.add("789");
System.out.println(list);
nameSet.addAll(list);
System.out.println(nameSet);
------解决方案--------------------
看了下你的原始要求,有点纳闷,你的names是个HashSet,里面的元素如果是String的话,怎么能重复的起来?
你试试看这段代码,难道你那边还能神奇的效果不一样?
HashSet<String> hs = new HashSet<String>();
hs.add(new String("123"));
hs.add(new String("123"));
hs.add(new String("123"));
hs.add(new String("123"));
System.out.println(hs.size());
------解决方案--------------------