copyOf metodu
Şöyle yaparız.
Örnek
Şöyle yaparız.
Şö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