java8 两个List对象合并和List的转换成Map

List转成成Map

public static void main(String[] args) {
List<String> idList = new ArrayList<>(Arrays.asList("姓名", "性别")); List<String> nameList = new ArrayList<>(Arrays.asList("杰克", "男"));
Map<String,String> listMap = idList.stream().collect(Collectors.toMap(key->key, key->nameList.get(idList.indexOf(key)))); System.out.println(listMap.toString()); }


输出:
{姓名=杰克, 性别=男}

  

 

posted @ 2021-03-05 17:43  星空异皓`  阅读(5420)  评论(0编辑  收藏  举报
/*页脚固定*/