package com.cetcnav.lbs.pis.stats.entity;
public class UserInfo implements java.io.Serializable {
private static final long serialVersionUID = 7902191860101550571L;
private String username;
private double fRate;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public double getfRate() {
return fRate;
}
public void setfRate(double fRate) {
this.fRate = fRate;
}
public UserInfo(String username, double fRate) {
super();
this.username = username;
this.fRate = fRate;
}
@Override
public String toString() {
return "UserInfo [username=" + username + ", fRate=" + fRate + "]";
}
}
public static void main(String[] args) throws Exception {
ListUtilsTest testObj = new ListUtilsTest();
List<UserInfo> list = new ArrayList<UserInfo>();
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
UserInfo user1 = new UserInfo("a",7.5d);
UserInfo user2 = new UserInfo("a",5.5d);
UserInfo user3 = new UserInfo("a",9.5d);
UserInfo user4 = new UserInfo("b",2.5d);
UserInfo user5 = new UserInfo("b",9.5d);
UserInfo user6 = new UserInfo("d",5.5d);
UserInfo user7 = new UserInfo("d",4.5d);
UserInfo user8 = new UserInfo("d",9.9d);
UserInfo user9 = new UserInfo("d",8.5d);
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
list.add(user5);
list.add(user6);
list.add(user7);
list.add(user8);
list.add(user9);
Map<String, List<UserInfo>> collect = list.stream().collect(Collectors.groupingBy(UserInfo::getUsername));
for(String key:collect.keySet()){
System.out.println(key+":" +collect.get(key).size());
System.out.println(collect.get(key));
}
}