其中对于四个字单姓的并未处理.
public static void main(String[] args) {
List<String> names = Stream.of("胡歌","林青霞","林风眠","曹知白","诸葛孔明").collect(Collectors.toList());
List<String> collect = names.stream()
.map(PinyinUtil::getPinyin)
.map(str -> str.split(" "))
.map(str -> str.length <= 3 ?
String.format("%s.%s@xxx.com", Arrays.stream(str).skip(1).collect(Collectors.joining("")), str[0]) :
String.format("%s.%s%s@xxx.com", Arrays.stream(str).skip(2).collect(Collectors.joining("")), str[0], str[1]))
.collect(Collectors.toList());
System.out.println(collect);
}
[ge.hu@xxx.com, qingxia.lin@xxx.com, fengmian.lin@xxx.com, zhibai.cao@xxx.com, kongming.zhuge@xxx.com]