编程语言
首页 > 编程语言> > java通过姓名生成邮箱账号

java通过姓名生成邮箱账号

作者:互联网

其中对于四个字单姓的并未处理.
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]

标签:map,java,账号,lin,xxx,names,str,邮箱,com
来源: https://www.cnblogs.com/lylhqy/p/16283043.html