Skip to content

Commit 3befd30

Browse files
authored
BAEL-4969: Improvement: Streams to Immutable Collections (eugenp#11026)
* add new module for java core 16 * format pom.xml
1 parent 16c3110 commit 3befd30

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant articles:
2+
3+
- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>core-java-16</artifactId>
7+
<version>0.1.0-SNAPSHOT</version>
8+
<name>core-java-16</name>
9+
<packaging>jar</packaging>
10+
<url>http://maven.apache.org</url>
11+
12+
<parent>
13+
<groupId>com.baeldung</groupId>
14+
<artifactId>parent-modules</artifactId>
15+
<version>1.0.0-SNAPSHOT</version>
16+
<relativePath>../../</relativePath>
17+
</parent>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.assertj</groupId>
22+
<artifactId>assertj-core</artifactId>
23+
<version>${assertj.version}</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<version>${maven-compiler-plugin.version}</version>
34+
<configuration>
35+
<source>${maven.compiler.source.version}</source>
36+
<target>${maven.compiler.target.version}</target>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</build>
41+
42+
<properties>
43+
<maven.compiler.source.version>16</maven.compiler.source.version>
44+
<maven.compiler.target.version>16</maven.compiler.target.version>
45+
<assertj.version>3.6.1</assertj.version>
46+
</properties>
47+
48+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.streams;
2+
3+
import java.util.List;
4+
import java.util.stream.Stream;
5+
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class StreamToImmutableUnitTest {
10+
11+
@Test
12+
public void whenUsingStreamToList_thenReturnImmutableList() {
13+
14+
List<String> immutableList = Stream.of("a", "b", "c", "d")
15+
.toList();
16+
17+
Assertions.assertThrows(UnsupportedOperationException.class, () -> {
18+
immutableList.add("e");
19+
});
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)