17 Aralık 2019 Salı

ImmutableSortedMap Sınıfı - TreeMap ile Benzeşir

copyOf metodu
Şöyle yaparız.
Map<String, Long> intermediateMap = Stream.of("b", "a", "c", "b")
  .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
ImmutableSortedMap<String, Long> desiredMap = ImmutableSortedMap.copyOf(intermediateMap);

System.out.println(desiredMap); // Outputs {a=1, b=2, c=1}, which is the desired state
toImmutableSortedMap metodu
Örnek
Şöyle yaparız.
 Map<String, Long> result =
        Stream.of("b", "a", "c", "b")
              .collect(ImmutableSortedMap.toImmutableSortedMap(
                  Comparator.naturalOrder(),
                  Function.identity(),
                  x -> 1L,
                  Long::sum
              ));

Hiç yorum yok:

Yorum Gönder