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:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user