public class demoTest {

@Test
public void text()
{
List<UserBean> list=new ArrayList<>();
UserBean userBean=new UserBean();
userBean.setPassword("123456");
userBean.setUsername("张三");
list.add(userBean);
UserBean userBean1=new UserBean();
userBean1.setPassword("123456");
userBean1.setUsername("李四");
list.add(userBean1);
UserBean userBean2=new UserBean();
userBean2.setPassword("123456");
userBean2.setUsername("李四");
list.add(userBean2);

List<UserBean> removeDuplicateUser = removeDuplicateUser(list);


for(UserBean data : removeDuplicateUser){
System.out.println(data.getUsername() + ":" + data.getPassword());
}
List<UserBean> list1 = sortUser(removeDuplicateUser);
for(UserBean data : list1){
System.out.println(data.getUsername() + ":" + data.getPassword());
}

}

/**
* 去重
*
* @param
* @return
* @author jqlin
*/
private static List<UserBean> removeDuplicateUser(List<UserBean> list) {
Set<UserBean> set = new TreeSet <UserBean>(new Comparator <UserBean>() {
@Override
public int compare(UserBean a, UserBean b) {
// 字符串则按照asicc码升序排列
return a.getUsername().compareTo(b.getUsername());
}
});

set.addAll(list);
return new ArrayList<UserBean>(set);
}

/**
* 排序,按照中文排序
*
* @param
* @return
* @author jqlin
*/
private static List<UserBean> sortUser(List<UserBean> list) {
Comparator comparator = Collator.getInstance(Locale.CHINESE);
Collections.sort(list, new Comparator<UserBean>() {
@Override
public int compare(UserBean o1, UserBean o2) {
return comparator.compare(o1.getUsername(), o2.getUsername());
}
});
return list;
}
}