Saravanan's Corner: Blackberry Dev

Saturday, 12 July 2025

Java 11 features

 Language Enhancements:

  • var in Lambda Expressions: Java 11 allows the use of var keyword for local variable type inference in lambda expressions, improving readability and consistency. 
Java
    list.forEach((var item) -> System.out.println(item)); // Example
2. New APIs:
  • String::isBlank()Checks if a string is empty or contains only whitespace characters. 
Java
    String str = "   ";    System.out.println(str.isBlank()); // true
  • String::strip()Removes leading and trailing whitespace, handling Unicode characters correctly. 
Java
    String str = "  hello  ";    System.out.println(str.strip()); // "hello"
  • String::lines()Returns a stream of lines from a string. 
  • Files::readString()Reads the entire content of a file into a string. 
  • HttpClientA new, asynchronous, and non-blocking HTTP client API supporting HTTP/1.1 and HTTP/2. 
  • Predicate::not()A static method that negates a predicate. 
Java
    Predicate<String> notEmpty = String::isEmpty;    Predicate<String> notEmptyNegated = Predicate.not(String::isEmpty);

  • New toArray method: A new toArray method in the Collection interface that takes an IntFunction argument for more convenient array creation. 

No comments:

Post a Comment