Discuss / Java / 转换

转换

Topic source
String[] array = new String[]{" 2019-12-31 ", "2020 - 01-09 ", "2020- 05 - 01 ", "2022 - 02 - 01", " 2025-01 -01"};
LocalDate[] array2 = Arrays.stream(array)
        .map(s -> s.replaceAll("\\s", ""))
        .map(LocalDate::parse)
        .toArray(LocalDate[]::new);

for (LocalDate localDate : array2) {
    System.out.println(localDate);
}

  • 1

Reply