javaintermediate
Java Stream Collector Grouping
Filter and collect transaction totals by currency using modern Java Streams
By ApeType Staff·16 lines·472 characters·1,420 total attempts
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public record Transaction(String currency, double amount) {}
public class Analytics {
public static Map<String, Double> summarize(List<Transaction> items) {
return items.stream()
.filter(t -> t.amount() > 0)
.collect(Collectors.groupingBy(
Transaction::currency,
Collectors.summingDouble(Transaction::amount)
));
}
}
TRANSCRIBE
Ready when you are.
Test your muscle memory and transcription speed against this exact snippet.
Start Typing
Tip: Press Esc anytime to restart
Best runs on this snippet
No recorded runs yet. Be the first to type this snippet!