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()); }


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

  

 

相关文章:

  • 2022-12-23
  • 2022-01-07
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-01-23
  • 2022-03-07
  • 2022-12-23
相关资源
相似解决方案