You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Try to use only the information given up to this point in this book.
7
+
- Try not to give up until you've given it a solid attempt
8
+
9
+
## Challenge 1.
10
+
11
+
Translate the following code using a for-loop to code using streams.
12
+
13
+
```java,editable
14
+
import module java.base;
15
+
16
+
class Main {
17
+
void main() {
18
+
for (int i = 0; i < 10; i++) {
19
+
IO.println(i);
20
+
}
21
+
}
22
+
}
23
+
```
24
+
25
+
## Challenge 2.
26
+
27
+
Translate the following code using a for-loop to code using streams.
28
+
29
+
```java
30
+
importmodulejava.base;
31
+
32
+
classMain {
33
+
voidmain() {
34
+
List<Integer> timestamps =List.of(1, 1756137441);
35
+
36
+
Set<Instant> instants =newHashSet<>();
37
+
for (int timestamp : timestamps) {
38
+
instants.add(Instant.ofEpochSecond(timestamp));
39
+
}
40
+
41
+
IO.println(instants);
42
+
}
43
+
}
44
+
```
45
+
46
+
## Challenge 3.
47
+
48
+
Read the documentation on [`Collector`](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/stream/Collector.html) and [`Collectors`](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/stream/Collector.html).
49
+
50
+
Make an implementation of `Collector` that can collect elements into `MySpecialList`.
0 commit comments