Java Reference
In-Depth Information
Operation Type
Return
type
Type/functional
interface used
Function
descriptor
forEach
Terminal
void
Consumer<T>
T -> void
collect
terminal
R
Collector<T, A, R>
reduce
Terminal
Optional<T>
BinaryOperator<T>
(T, T) -> T
(stateful-bounded)
count
Terminal
long
5.5. Putting it all into practice
In this section, you get to practice what you've learned about streams so far. We give a different
domain: traders executing transactions. You're asked by your manager to find answers to eight
queries. Can you do it? We give the solutions in
section 5.5.2
, but you should try them yourself
first to get some practice.
1
. Find all transactions in the year 2011 and sort them by value (small to high).
2
. What are all the unique cities where the traders work?
3
. Find all traders from Cambridge and sort them by name.
4
. Return a string of all traders' names sorted alphabetically.
5
. Are any traders based in Milan?
6
. Print all transactions' values from the traders living in Cambridge.
7
. What's the highest value of all the transactions?
8
. Find the transaction with the smallest value.
5.5.1. The domain: Traders and Transactions
Here's the domain you'll be working with, a list of Traders and Transactions:
Trader raoul = new Trader("Raoul", "Cambridge");
Search WWH ::
Custom Search