Gaurav
S
alvi
New Features Of Java (post version 8)
This cheatsheet is to list new features which i use it generally during programming. Note - Only standard features are listed and preview ones are ignored.
Java 9
New factory methods in collections:
List.of(),Map.of(),Set.of().Stream has new
iterateandtakeWhilemethod.Optionals -
ifPresentOrElsemethod.Interfaces can have private methods.
Java 10
varkeyword - local variable type inference
Java 11
String has new methods :
isBlank(),.lines(),.strip()varcan be used in lambdas also along with its previous support in method scopes.
Java 14
Switch Expressions
Helpful NullPointerException - Exception now also shows variable which was null
Java 15
- Text Blocks
Allows defining multiline string literal.
public class TextBlockDemo {
private static String textBlock = """
Hello World !
I am a multi-line text block and
you can start using me starting Java 15
""";
public static void main(String[] args) {
String localTextBlock = """
I am another text block
but as a local variable
""";
System.out.println(textBlock);
System.out.println(localTextBlock);
}
}
Helpful to define String variables like JSON, HTML, CSV, etc.
Hope you find this useful.
For any comments feel free to contact on: grsalvi@gmail.com
Share