Changes in Java12

Switch expression

It has been revamped to act as an expression. It removes the usage of break.

switch(day) {
  case SATURDAY, SUNDAY -> System.out.println(1);
  case TUESDAY, FRIDAY -> System.out.println(2);
  case THURSDAY, MONDAY -> System.out.println(3);
  case WEDNESDAY -> System.out.println(4);

Teeing collectors

Allows to collect two pieces of information from a stream pipeline.
For example, I want to obtain min and max from an Stream<Integer> to create a range.

final List<Integer> list = Lists.of(1, 2, 5, 8);
final Range<Integer> range =
           // custom created Range factory.


API Changes

  • new String.format() method to indent and format Strings
  • better error recovery in CompletableFuture
  • new CompactNumberFormat to format numbers in a fashionable way
  • new method Files.mismatch(file1, file2), compares two files and returns the index of the first byte where they differ or -1


New garbage collection (GC) algorithm made for applications who prefer responsiveness and predictable short pauses.