BAEL-3938: Add new section on Java 10 Collectors.toUnmodifiableList() (#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
This commit is contained in:
parent
e26aebc76f
commit
fc5d08d3f6
|
@ -11,3 +11,4 @@ This module contains articles about Java 10 core features
|
|||
- [Copying Sets in Java](https://www.baeldung.com/java-copy-sets)
|
||||
- [Converting between a List and a Set in Java](https://www.baeldung.com/convert-list-to-set-and-set-to-list)
|
||||
- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception)
|
||||
- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.java10.streams;
|
||||
|
||||
import static java.util.stream.Collectors.toUnmodifiableList;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StreamToImmutableJava10UnitTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingCollectorsToUnmodifiableList_thenSuccess() {
|
||||
List<String> givenList = Arrays.asList("a", "b", "c");
|
||||
List<String> result = givenList.stream()
|
||||
.collect(toUnmodifiableList());
|
||||
|
||||
System.out.println(result.getClass());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue