Java 13 for competitive programming

Правка en1, от eatmore, 2019-09-18 14:58:23

Java 13 has been released a few days ago. Here are some changes that may be useful for competitive programming.

  • Switch expressions: first introduced in Java 12. In Java 13, a value is returned from a switch expression using yield statement:
String numType = switch (num) {
	0 -> "zero";
	1 -> "one";
	default -> {
		for (int i = 2; i < num; i++) {
			if (num % i == 0) {
				yield "composite";
			}
		}
		yield "prime";
	}
};
  • Text blocks: multi-line string literals, similar to Python:
String input = """
	3 3
	1 2
	1 3
	2 3""";

If you know about other useful features, post it here.

Previous posts: Java 8, 9, 10, 11 and 12.

Теги java, java 13

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский eatmore 2019-09-18 14:58:23 832 Initial revision (published)