Grokking Java Interview Questions
0% completed
Predict the Output: Collections and Streams
Two pieces of collection code can look almost the same and still produce different results. A list may be a view of another list, a method may return an object without storing it, and two stream operations may be written in another order.
The six programs that follow use lists, maps, comparators, and streams from the cart and the orders of an online store. Predict each printed line before you run the code.
Program 1: A Part of a List
The method subList(1, 4) selects the elements at the indexes 1, 2, and 3 of the cart.
<details><summary>Show answer</summary>
**The program prints
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%