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()); }
输出:
{姓名=杰克, 性别=男}