Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6u469kis46DspusiL
22 lines
1.0 KiB
Plaintext
22 lines
1.0 KiB
Plaintext
== Q7: TreeSet and a comparator that says 'equal' ==
|
|
TreeSet by length only: [fig, apple] (3 words added, size 2)
|
|
length then natural: [fig, apple, grape]
|
|
== Q8: List<Integer>.remove(int) vs remove(Object) ==
|
|
remove(1) -> [10, 30]
|
|
remove(Integer.valueOf(10)) -> [20, 30]
|
|
== Q9: Collectors.toMap with a duplicate key ==
|
|
toMap(city, amount) -> IllegalStateException: Duplicate key Pune (attempted merging values 100 and 250)
|
|
toMap with Integer::sum -> {Mumbai=300, Pune=350}
|
|
groupingBy + counting -> {Mumbai=1, Pune=2}
|
|
== Q10: streams are lazy ==
|
|
no terminal operation: elements touched = 0
|
|
findFirst() on evens: result = 2, elements touched = 2
|
|
== Q11: Optional.orElse vs orElseGet ==
|
|
orElse(expensiveDefault()) -> default computed 1 time(s)
|
|
orElseGet(expensiveDefault) -> default computed 0 time(s)
|
|
== Q12: comparator chain with nulls ==
|
|
Employee[name=Kiran, dept=Eng, salary=80000]
|
|
Employee[name=Meera, dept=Sales, salary=120000]
|
|
Employee[name=Asha, dept=Sales, salary=90000]
|
|
Employee[name=Ravi, dept=null, salary=70000]
|