文章目录

  • 将 List 转 数组
    • List.toArra()
    • Stream().toArray()
  • 将 数组 转 List
    • Lists.newArrayList()
    • Stream.of()

将 List 转 数组

List.toArra()

List<Integer> list = Lists.newArrayList(1, 2, 3);// 无需转换类型 --> [1,2,3]Integer[] intArray = list.toArray(new Integer[0]);

Stream().toArray()

List<Integer> list = Lists.newArrayList(1, 2, 3);// 需要转换类型 --> ["1","2","3"]String[] strArray = list.stream().map(String::valueOf).toArray(String[]::new);

将 数组 转 List

Lists.newArrayList()

String[] arr = {"1", "2", "3"};// 无需转换类型 --> ["1","2","3"]List<String> list = Lists.newArrayList(arr);

Stream.of()

String[] arr = {"1", "2", "3"};// 需要转换类型 --> [1,2,3]List<Integer> list = Stream.of(arr).map(Integer::parseInt).collect(Collectors.toList());