Map<String, EmailAddress> mapAliasAddress;
mapAliasAddress = Files.lines(Paths.get("emails.csv"))
.map(s->s.split(","))
.collect(Collectors.groupBy(s->s[1], new EmailAddress(s->s[1],s->[0])));// first is the alias, second is the email address
这是EmailAddress一个对象类,它接受两个参数(别名和email_address)
答案 0 :(得分:2)
我认为这会做你想做的事情:
Map<String, EmailAddress> mapAliasAddress;
mapAliasAddress = Files.lines(Paths.get("emails.csv"))
.map(s->s.split(","))
.collect(Collectors.toMap(s -> s[1], s -> new EmailAddress(s[1], s[0]);