Skip to content

Commit 91fff1c

Browse files
authored
BAEL-3938: Add new section on Java 10 Collectors.toUnmodifiableList() (eugenp#10488)
* Add java10 examples in the style of the existing examples The existing examples in core-java-streams-2 module still had system out in them instead of assertions, so I kept that style to keep the article consistent. * Remove code example that is not in the article
1 parent ad80720 commit 91fff1c

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

core-java-modules/core-java-10/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ This module contains articles about Java 10 core features
1111
- [Copying Sets in Java](https://www.baeldung.com/java-copy-sets)
1212
- [Converting between a List and a Set in Java](https://www.baeldung.com/convert-list-to-set-and-set-to-list)
1313
- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception)
14+
- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.java10.streams;
2+
3+
import static java.util.stream.Collectors.toUnmodifiableList;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
8+
import org.junit.Test;
9+
10+
public class StreamToImmutableJava10UnitTest {
11+
12+
@Test
13+
public void whenUsingCollectorsToUnmodifiableList_thenSuccess() {
14+
List<String> givenList = Arrays.asList("a", "b", "c");
15+
List<String> result = givenList.stream()
16+
.collect(toUnmodifiableList());
17+
18+
System.out.println(result.getClass());
19+
}
20+
}

0 commit comments

Comments
 (0)