Table of contents
  1. Optionals
  2. Streams
    1. Map and Collect
    2. ConcurrentHashMap and LinkedList
    3. Map to String




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));

}