Discuss / Java / 作业

作业

Topic source

shadowTy

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {
	public static void main(String[] args) {
		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(s->s.replaceAll("\\s", "")).map(s->LocalDate.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd"))).forEach(s->System.out.println(s.toString()));
	}
}

  • 1

Reply