Table of contents
  1. Optionals
  2. Streams
    1. Map and Collect
    2. ConcurrentHashMap and LinkedList
    3. Map to String
  3. Sealed Classes
  4. Pattern Matching
    1. Scope of Variables
  5. Records
  6. Text Block (String)
  7. Switch (Case)
  8. Local Variable Type Interface (Var)
    1. var with lambda
  9. Private Interface Methods
  10. Try
  11. Diamond Operator
    1. For Anonymous Inner Class




Optionals

public class OptEx {
    Optional<Map<String, String>> aorMap = Optional.ofNullable(this.customAORMap);

}

Streams

Map and Collect


public class MapExample {

    Map newMap = clientEntityMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(e -> {
        String externalCode = e.getDescription();
        String externalCode = e.getDescription();
        String externalCode = e.getDescription();

        return Map.of("externalCode", "");
    }).collect(Collectors.toList())));
}

ConcurrentHashMap and LinkedList

public class LinkedListEx {
    Map newMap = this.clientEntityMap.entrySet()
                                     .stream()
                                     .map(entry -> Map.entry(entry.getKey(), entry.getValue()
                                                                                  .stream()
                                                                                  .map(ClientEntityDetails::toMap)
                                                                                  .collect(Collectors.toCollection(LinkedList::new))))
                                     .collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, ConcurrentHashMap::new));

}

Map to String

public class MapToString {
    Map mapToString = this.clientEntityMap.entrySet()
                                          .stream()
                                          .map(entry -> Map.entry(entry.getKey(), entry.getValue()
                                                                                       .stream()
                                                                                       .map(ClientEntityDetails::toMap)
                                                                                       .collect(Collectors.toCollection(LinkedList::new))))
                                          .collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, ConcurrentHashMap::new));

}

Sealed Classes

img.png

Pattern Matching

img.png

Scope of Variables

img.png

Records

img.png

Text Block (String)

img.png
img.png

Switch (Case)

img.png
img.png

Local Variable Type Interface (Var)

img_1.png

var with lambda

img.png

Private Interface Methods

img.png

Try

img.png

Diamond Operator

For Anonymous Inner Class

img.png