Discuss / Java / 练习:使用map()把一组String转换为LocalDate并打印

练习:使用map()把一组String转换为LocalDate并打印

Topic source

jasmine

#1 Created at ... [Delete] [Delete and Lock User]
  String[] array = new String[] { " 2019-12-31 ", "2020 - 01-09 ", "2020- 05 - 01 ", "2022 - 02 - 01",
                " 2025-01 -01" };
        // 请使用map把String[]转换为LocalDate并打印:
        Arrays.stream(array)
                .map(str-> str.replaceAll(" ",""))
                .map(LocalDate::parse)
                .forEach(System.out::println);

  • 1

Reply