From 3befd30ef4056d139dcea9dbffac2e5b1d911707 Mon Sep 17 00:00:00 2001
From: Azhwani <13301425+azhwani@users.noreply.github.com>
Date: Thu, 15 Jul 2021 06:18:47 +0200
Subject: [PATCH] BAEL-4969: Improvement: Streams to Immutable Collections
(#11026)
* add new module for java core 16
* format pom.xml
---
core-java-modules/core-java-16/README.md | 3 ++
core-java-modules/core-java-16/pom.xml | 48 +++++++++++++++++++
.../streams/StreamToImmutableUnitTest.java | 23 +++++++++
3 files changed, 74 insertions(+)
create mode 100644 core-java-modules/core-java-16/README.md
create mode 100644 core-java-modules/core-java-16/pom.xml
create mode 100644 core-java-modules/core-java-16/src/test/java/com/baeldung/streams/StreamToImmutableUnitTest.java
diff --git a/core-java-modules/core-java-16/README.md b/core-java-modules/core-java-16/README.md
new file mode 100644
index 0000000000..760513189f
--- /dev/null
+++ b/core-java-modules/core-java-16/README.md
@@ -0,0 +1,3 @@
+### Relevant articles:
+
+- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
diff --git a/core-java-modules/core-java-16/pom.xml b/core-java-modules/core-java-16/pom.xml
new file mode 100644
index 0000000000..230e342f01
--- /dev/null
+++ b/core-java-modules/core-java-16/pom.xml
@@ -0,0 +1,48 @@
+
+
+ 4.0.0
+ core-java-16
+ 0.1.0-SNAPSHOT
+ core-java-16
+ jar
+ http://maven.apache.org
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ../../
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.source.version}
+ ${maven.compiler.target.version}
+
+
+
+
+
+
+ 16
+ 16
+ 3.6.1
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-16/src/test/java/com/baeldung/streams/StreamToImmutableUnitTest.java b/core-java-modules/core-java-16/src/test/java/com/baeldung/streams/StreamToImmutableUnitTest.java
new file mode 100644
index 0000000000..afd7369d8d
--- /dev/null
+++ b/core-java-modules/core-java-16/src/test/java/com/baeldung/streams/StreamToImmutableUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.streams;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class StreamToImmutableUnitTest {
+
+ @Test
+ public void whenUsingStreamToList_thenReturnImmutableList() {
+
+ List immutableList = Stream.of("a", "b", "c", "d")
+ .toList();
+
+ Assertions.assertThrows(UnsupportedOperationException.class, () -> {
+ immutableList.add("e");
+ });
+
+ }
+
+}