diff --git a/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/tostring/ListToStringUnitTest.java b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/tostring/ListToStringUnitTest.java index 479ccaf92f..92e85099fe 100644 --- a/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/tostring/ListToStringUnitTest.java +++ b/core-java-modules/core-java-collections-list-4/src/test/java/com/baeldung/list/tostring/ListToStringUnitTest.java @@ -27,15 +27,13 @@ class ListToStringUnitTest { List arraysAsList = Arrays.asList("ONE", "TWO", "THREE"); StringJoiner stringJoiner = new StringJoiner(","); - arraysAsList.stream() - .forEach(v -> stringJoiner.add(v)); + arraysAsList.forEach(stringJoiner::add); String commaSeparatedString = stringJoiner.toString(); assertThat(commaSeparatedString).isEqualTo("ONE,TWO,THREE"); StringJoiner stringJoinerWithDelimiterPrefixSuffix = new StringJoiner(",", "[", "]"); - arraysAsList.stream() - .forEach(v -> stringJoinerWithDelimiterPrefixSuffix.add(v)); + arraysAsList.forEach(stringJoinerWithDelimiterPrefixSuffix::add); String commaSeparatedStringWithDelimiterPrefixSuffix = stringJoinerWithDelimiterPrefixSuffix.toString(); assertThat(commaSeparatedStringWithDelimiterPrefixSuffix).isEqualTo("[ONE,TWO,THREE]");