diff --git a/.github/ISSUE_TEMPLATE/issue_report.md b/.github/ISSUE_TEMPLATE/issue_report.md
new file mode 100644
index 0000000000..4bc8c8121c
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/issue_report.md
@@ -0,0 +1,32 @@
+---
+name: Issue Report
+about: Report an issue to help us improve
+title: '[ISSUE] '
+---
+
+**Article and Module Links**
+A link to the affected article and the affected module. You can find the link to the module in the Conclusion section in the "on Github" standard phase.
+
+**Describe the Issue**
+A clear and concise description of what the issue is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected Behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Environment (please complete the following information):**
+- OS: [e.g. Windows]
+- Browser [e.g. chrome, safari]
+- Version [e.g. 22]
+
+**Additional Context**
+Add any other context about the issue here.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000000..642f4c6707
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,11 @@
+# Contributing to Baeldung Tutorials
+First off, thank you for considering contributing to Baeldung Tutorials.
+
+## Reporting Issues
+Before you submit an issue, please review the guidelines below:
+
+1. **No Custom Modifications:** If your issue arises from any custom modifications you've made to the code in the repository, we won't be able to assist. We can only help if the issue is reproducible with the untouched codebase from this repo. If you're working with a modified version, consider asking for help on StackOverflow or other relevant forums.
+2. **Use a clear and descriptive title** for the issue to identify the problem.
+3. **Include a link to the article** you're having issues with.
+4. **Describe the exact steps which reproduce the problem** in as many details as possible.
+5. **Additional Details:** Offer any other context or descriptions that could be useful. Screenshots, error messages, copy/pasteable snippets, or logs can be immensely helpful.
\ No newline at end of file
diff --git a/apache-poi-3/README.md b/apache-poi-3/README.md
new file mode 100644
index 0000000000..9e9d6a94eb
--- /dev/null
+++ b/apache-poi-3/README.md
@@ -0,0 +1,3 @@
+## Relevant Articles
+- [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list)
+- [Expand Columns with Apache POI](https://www.baeldung.com/java-apache-poi-expand-columns)
diff --git a/apache-poi-3/pom.xml b/apache-poi-3/pom.xml
index 5031e1c5c7..905db3d58c 100644
--- a/apache-poi-3/pom.xml
+++ b/apache-poi-3/pom.xml
@@ -24,10 +24,74 @@
poi-scratchpad
${poi.version}
+
+
+ com.github.ozlerhakan
+ poiji
+ ${poiji.version}
+
+
+
+
+ org.apache.poi
+ poi
+ ${poi.version}
+
+
+
+ org.apache.poi
+ poi-ooxml-schemas
+ 4.1.2
+
+
+
+ org.apache.xmlbeans
+ xmlbeans
+ 5.1.1
+
+
+
+ org.apache.commons
+ commons-collections4
+ 4.4
+
+
+
+ org.dhatim
+ fastexcel
+ ${fastexcel.version}
+
+
+
+ org.dhatim
+ fastexcel-reader
+ ${fastexcel.version}
+
+
+
+ net.sourceforge.jexcelapi
+ jxl
+ ${jxl.version}
+
+
+
+ org.apache.logging.log4j
+ log4j-api
+ 2.17.1
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.17.1
+
5.2.3
+ 4.1.1
+ 0.15.7
+ 2.6.12
\ No newline at end of file
diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java
new file mode 100644
index 0000000000..b8fe4522de
--- /dev/null
+++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java
@@ -0,0 +1,54 @@
+package com.baeldung.convert.exceldatatolist;
+
+import com.poiji.annotation.ExcelCellName;
+
+public class FoodInfo {
+
+ @ExcelCellName("Category")
+ private String category; //food category
+ @ExcelCellName("Name")
+ private String name; // food name
+ @ExcelCellName("Measure")
+ private String measure;
+ @ExcelCellName("Calories")
+ private double calories; //amount of calories in kcal/measure
+
+ @Override
+ public String toString() {
+ return "FoodInfo{" + "category='" + category + '\'' + ", name='" + name + '\'' + ", measure='" + measure + '\'' + ", calories=" + calories + "} \n";
+ }
+
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getMeasure() {
+ return measure;
+ }
+
+ public void setMeasure(String measure) {
+ this.measure = measure;
+ }
+
+ public double getCalories() {
+ return calories;
+ }
+
+ public void setCalories(double calories) {
+ this.calories = calories;
+ }
+
+}
diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java
new file mode 100644
index 0000000000..87d31520e6
--- /dev/null
+++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java
@@ -0,0 +1,42 @@
+package com.baeldung.convert.exceldatatolist.fastexcel;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.dhatim.fastexcel.reader.ReadableWorkbook;
+import org.dhatim.fastexcel.reader.Row;
+import org.dhatim.fastexcel.reader.Sheet;
+
+import com.baeldung.convert.exceldatatolist.FoodInfo;
+
+public class ExcelDataToListOfObjectsFastExcel {
+ public static List excelDataToListOfObjets_withFastExcel(String fileLocation)throws IOException, NumberFormatException {
+ List foodData = new ArrayList();
+
+ try (FileInputStream file = new FileInputStream(fileLocation);
+ ReadableWorkbook wb = new ReadableWorkbook(file)) {
+ Sheet sheet = wb.getFirstSheet();
+ for (Row row:
+ sheet.read()
+ ) {
+ if(row.getRowNum() == 1) {
+ continue;
+ }
+ FoodInfo food = new FoodInfo();
+ food.setCategory(row.getCellText(0));
+ food.setName(row.getCellText(1));
+ food.setMeasure(row.getCellText(2));
+ food.setCalories(Double.parseDouble(row.getCellText(3)));
+
+ foodData.add(food);
+
+ }
+ }
+
+ return foodData;
+ }
+}
diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java
new file mode 100644
index 0000000000..61ba5e4700
--- /dev/null
+++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java
@@ -0,0 +1,37 @@
+package com.baeldung.convert.exceldatatolist.jexcelapi;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.baeldung.convert.exceldatatolist.FoodInfo;
+
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.read.biff.BiffException;
+
+public class ExcelDataToListOfObjectsJxl {
+ public static List excelDataToListOfObjets_withJxl(String fileLocation) throws IOException, BiffException {
+
+ List foodData = new ArrayList();
+
+ Workbook workbook = Workbook.getWorkbook(new File(fileLocation));
+ Sheet sheet = workbook.getSheet(0);
+
+ int rows = sheet.getRows();
+
+ for (int i = 1; i < rows; i++) {
+ FoodInfo foodInfo = new FoodInfo();
+
+ foodInfo.setCategory(sheet.getCell(0, i).getContents());
+ foodInfo.setName(sheet.getCell(1, i).getContents());
+ foodInfo.setMeasure(sheet.getCell(2, i).getContents());
+ foodInfo.setCalories(Double.parseDouble(sheet.getCell(3, i).getContents()));
+
+ foodData.add(foodInfo);
+
+ }
+ return foodData;
+ }
+}
diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java
new file mode 100644
index 0000000000..8b568b889a
--- /dev/null
+++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java
@@ -0,0 +1,39 @@
+package com.baeldung.convert.exceldatatolist.poi;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import com.baeldung.convert.exceldatatolist.FoodInfo;
+
+public class ExcelDataToListApachePOI {
+ public static List excelDataToListOfObjets_withApachePOI(String fileLocation) throws IOException {
+ FileInputStream file = new FileInputStream(new File(fileLocation));
+ Workbook workbook = new XSSFWorkbook(file);
+ Sheet sheet = workbook.getSheetAt(0);
+ List foodData = new ArrayList();
+ DataFormatter dataFormatter = new DataFormatter();
+ for (int n = 1; n < sheet.getPhysicalNumberOfRows(); n++) {
+ Row row = sheet.getRow(n);
+ FoodInfo foodInfo = new FoodInfo();
+ int i = row.getFirstCellNum();
+
+ foodInfo.setCategory(dataFormatter.formatCellValue(row.getCell(i)));
+ foodInfo.setName(dataFormatter.formatCellValue(row.getCell(++i)));
+ foodInfo.setMeasure(dataFormatter.formatCellValue(row.getCell(++i)));
+ foodInfo.setCalories(Double.parseDouble(dataFormatter.formatCellValue(row.getCell(++i))));
+
+ foodData.add(foodInfo);
+
+ }
+ return foodData;
+ }
+}
diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java
new file mode 100644
index 0000000000..be190d38f7
--- /dev/null
+++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java
@@ -0,0 +1,13 @@
+package com.baeldung.convert.exceldatatolist.poiji;
+
+import java.io.File;
+import java.util.List;
+
+import com.baeldung.convert.exceldatatolist.FoodInfo;
+import com.poiji.bind.Poiji;
+
+public class ExcelDataToListOfObjectsPOIJI {
+ public static List excelDataToListOfObjets_withPOIJI(String fileLocation){
+ return Poiji.fromExcel(new File(fileLocation), FoodInfo.class);
+ }
+}
diff --git a/apache-poi-3/src/main/resources/food_info.xls b/apache-poi-3/src/main/resources/food_info.xls
new file mode 100644
index 0000000000..1377d8e18d
Binary files /dev/null and b/apache-poi-3/src/main/resources/food_info.xls differ
diff --git a/apache-poi-3/src/main/resources/food_info.xlsx b/apache-poi-3/src/main/resources/food_info.xlsx
new file mode 100644
index 0000000000..c604ff367d
Binary files /dev/null and b/apache-poi-3/src/main/resources/food_info.xlsx differ
diff --git a/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java b/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java
new file mode 100644
index 0000000000..5d65c04b31
--- /dev/null
+++ b/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java
@@ -0,0 +1,53 @@
+package com.baeldung.convert.exceldatatolist;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+// import org.junit.jupiter.api.Test;
+// import static org.junit.jupiter.api.Assertions.*;
+import org.junit.Test;
+
+import com.baeldung.convert.exceldatatolist.fastexcel.ExcelDataToListOfObjectsFastExcel;
+import com.baeldung.convert.exceldatatolist.jexcelapi.ExcelDataToListOfObjectsJxl;
+import com.baeldung.convert.exceldatatolist.poi.ExcelDataToListApachePOI;
+import com.baeldung.convert.exceldatatolist.poiji.ExcelDataToListOfObjectsPOIJI;
+
+import jxl.read.biff.BiffException;
+
+public class ExcelDataToListOfObjectsUnitTest {
+
+ @Test
+ public void whenParsingExcelFileWithPOIJI_thenConvertsToList() throws IOException {
+ List foodInfoList = ExcelDataToListOfObjectsPOIJI.excelDataToListOfObjets_withPOIJI("src/main/resources/food_info.xlsx");
+
+ assertEquals("Beverages", foodInfoList.get(0).getCategory());
+ assertEquals("Dairy", foodInfoList.get(3).getCategory());
+ }
+
+ @Test
+ public void whenParsingExcelFileWithApachePOI_thenConvertsToList() throws IOException {
+ List foodInfoList = ExcelDataToListApachePOI.excelDataToListOfObjets_withApachePOI("src/main/resources/food_info.xlsx");
+
+ assertEquals("Beverages", foodInfoList.get(0).getCategory());
+ assertEquals("Dairy", foodInfoList.get(3).getCategory());
+ }
+
+ @Test
+ public void whenParsingExcelFileWithFastExcel_thenConvertsToList() throws IOException {
+ List foodInfoList = ExcelDataToListOfObjectsFastExcel.excelDataToListOfObjets_withFastExcel("src/main/resources/food_info.xlsx");
+
+ assertEquals("Beverages", foodInfoList.get(0).getCategory());
+ assertEquals("Dairy", foodInfoList.get(3).getCategory());
+ }
+
+ @Test
+ public void whenParsingExcelFileWithJxl_thenConvertsToList() throws IOException, BiffException {
+ List foodInfoList = ExcelDataToListOfObjectsJxl.excelDataToListOfObjets_withJxl("src/main/resources/food_info.xls");
+
+ assertEquals("Beverages", foodInfoList.get(0).getCategory());
+ assertEquals("Dairy", foodInfoList.get(3).getCategory());
+ }
+
+}
diff --git a/core-java-modules/core-java-16/README.md b/core-java-modules/core-java-16/README.md
index b2740d194c..11b0fba8d3 100644
--- a/core-java-modules/core-java-16/README.md
+++ b/core-java-modules/core-java-16/README.md
@@ -5,3 +5,4 @@
- [Collecting Stream Elements into a List in Java](https://www.baeldung.com/java-stream-to-list-collecting)
- [New Features in Java 16](https://www.baeldung.com/java-16-new-features)
- [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector)
+- [Value-Based Classes in Java](https://www.baeldung.com/java-value-based-classes)
diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md
index 2e7130c906..2c51db275a 100644
--- a/core-java-modules/core-java-21/README.md
+++ b/core-java-modules/core-java-21/README.md
@@ -1,2 +1,3 @@
## Relevant Articles
- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections)
+- [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates)
diff --git a/core-java-modules/core-java-21/pom.xml b/core-java-modules/core-java-21/pom.xml
index 83b2b1c858..7b8fa9063f 100644
--- a/core-java-modules/core-java-21/pom.xml
+++ b/core-java-modules/core-java-21/pom.xml
@@ -12,23 +12,36 @@
0.0.1-SNAPSHOT
-
-
-
-
-
-
-
-
-
-
-
-
+
+ 21
+ 21
+ UTF-8
+
-
-
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 21
+
+ false
+
+ --enable-preview
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ --enable-preview
+
+
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java
new file mode 100644
index 0000000000..7e66144f1c
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java
@@ -0,0 +1,37 @@
+package com.baeldung.stringtemplates;
+
+import java.text.MessageFormat;
+
+public class StringCompositionTechniques {
+ String composeUsingPlus(String feelsLike, String temperature, String unit) {
+ return "Today's weather is " + feelsLike + ", with a temperature of " + temperature + " degrees " + unit;
+ }
+
+ String composeUsingStringBuffer(String feelsLike, String temperature, String unit) {
+ return new StringBuffer().append("Today's weather is ")
+ .append(feelsLike)
+ .append(", with a temperature of ")
+ .append(temperature)
+ .append(" degrees ")
+ .append(unit)
+ .toString();
+ }
+
+ String composeUsingStringBuilder(String feelsLike, String temperature, String unit) {
+ return new StringBuilder().append("Today's weather is ")
+ .append(feelsLike)
+ .append(", with a temperature of ")
+ .append(temperature)
+ .append(" degrees ")
+ .append(unit)
+ .toString();
+ }
+
+ String composeUsingFormatters(String feelsLike, String temperature, String unit) {
+ return String.format("Today's weather is %s, with a temperature of %s degrees %s", feelsLike, temperature, unit);
+ }
+
+ String composeUsingMessageFormatter(String feelsLike, String temperature, String unit) {
+ return MessageFormat.format("Today''s weather is {0}, with a temperature of {1} degrees {2}", feelsLike, temperature, unit);
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java
new file mode 100644
index 0000000000..0fb18a84e9
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java
@@ -0,0 +1,56 @@
+package com.baeldung.stringtemplates;
+
+import static java.lang.StringTemplate.RAW;
+import static java.util.FormatProcessor.FMT;
+
+public class StringTemplateExamples {
+ String interpolationUsingSTRProcessor(String feelsLike, String temperature, String unit) {
+ return STR
+ . "Today's weather is \{ feelsLike }, with a temperature of \{ temperature } degrees \{ unit }" ;
+ }
+
+ String interpolationOfJSONBlock(String feelsLike, String temperature, String unit) {
+ return STR
+ . """
+ {
+ "feelsLike": "\{ feelsLike }",
+ "temperature": "\{ temperature }",
+ "unit": "\{ unit }"
+ }
+ """ ;
+ }
+
+ String interpolationWithExpressions() {
+ return STR
+ . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ;
+ }
+
+ String interpolationWithTemplates() {
+ StringTemplate str = RAW
+ . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ;
+ return STR.process(str);
+ }
+
+ String interpolationOfJSONBlockWithFMT(String feelsLike, float temperature, String unit) {
+ return FMT
+ . """
+ {
+ "feelsLike": "%1s\{ feelsLike }",
+ "temperature": "%2.2f\{ temperature }",
+ "unit": "%1s\{ unit }"
+ }
+ """ ;
+ }
+
+ private String getFeelsLike() {
+ return "pleasant";
+ }
+
+ private String getTemperature() {
+ return "25";
+ }
+
+ private String getUnit() {
+ return "Celsius";
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java
new file mode 100644
index 0000000000..8f51c03539
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java
@@ -0,0 +1,11 @@
+package com.baeldung.unnamed.variables;
+
+public record Car(String name, String color, T engine) { }
+
+abstract class Engine { }
+
+class GasEngine extends Engine { }
+
+class ElectricEngine extends Engine { }
+
+class HybridEngine extends Engine { }
\ No newline at end of file
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java
new file mode 100644
index 0000000000..310ce621f9
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java
@@ -0,0 +1,50 @@
+package com.baeldung.unnamed.variables;
+
+public class UnnamedPatterns {
+
+ static String getObjectsColorWithNamedPattern(Object object) {
+ if (object instanceof Car(String name, String color, Engine engine)) {
+ return color;
+ }
+ return "No color!";
+ }
+
+ static String getObjectsColorWithUnnamedPattern(Object object) {
+ if (object instanceof Car(_, String color, _)) {
+ return color;
+ }
+ return "No color!";
+ }
+
+ static String getObjectsColorWithSwitchAndNamedPattern(Object object) {
+ return switch (object) {
+ case Car(String name, String color, Engine engine) -> color;
+ default -> "No color!";
+ };
+ }
+
+ static String getObjectsColorWithSwitchAndUnnamedPattern(Object object) {
+ return switch (object) {
+ case Car(_, String color, _) -> color;
+ default -> "No color!";
+ };
+ }
+
+ static String getEngineTypeWithNamedPattern(Car> car) {
+ return switch (car) {
+ case Car(String name, String color, GasEngine engine) -> "gas";
+ case Car(String name, String color, ElectricEngine engine) -> "electric";
+ case Car(String name, String color, HybridEngine engine) -> "hybrid";
+ default -> "none";
+ };
+ }
+
+ static String getEngineTypeWithUnnamedPattern(Car> car) {
+ return switch (car) {
+ case Car(_, _, GasEngine _) -> "gas";
+ case Car(_, _, ElectricEngine _) -> "electric";
+ case Car(_, _, HybridEngine _) -> "hybrid";
+ default -> "none";
+ };
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java
new file mode 100644
index 0000000000..82e76b40a4
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java
@@ -0,0 +1,134 @@
+package com.baeldung.unnamed.variables;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+class Transaction implements AutoCloseable {
+
+ @Override
+ public void close() {
+ System.out.println("Closed!");
+ }
+}
+
+public class UnnamedVariables {
+
+ static int countCarsOverLimitWithNamedVariable(Collection> cars, int limit) {
+ var total = 0;
+ var totalOverLimit = 0;
+ for (var car : cars) {
+ total++;
+ if (total > limit) {
+ totalOverLimit++;
+ // side effect
+ }
+ }
+ return totalOverLimit;
+ }
+
+ static int countCarsOverLimitWithUnnamedVariable(Collection> cars, int limit) {
+ var total = 0;
+ var totalOverLimit = 0;
+ for (var _ : cars) {
+ total++;
+ if (total > limit) {
+ totalOverLimit++;
+ // side effect
+ }
+ }
+ return totalOverLimit;
+ }
+
+ static void sendNotificationToCarsWithNamedVariable(Collection> cars) {
+ sendOneTimeNotification();
+ for (int i = 0; i < cars.size(); i++) {
+ // Notify car
+ }
+ }
+
+ static void sendNotificationToCarsWithUnnamedVariable(Collection> cars) {
+ for (int i = 0, _ = sendOneTimeNotification(); i < cars.size(); i++) {
+ // Notify car
+ }
+ }
+
+ private static int sendOneTimeNotification() {
+ System.out.println("Sending one time notification!");
+ return 1;
+ }
+
+ static Car> removeThreeCarsAndReturnFirstRemovedWithNamedVariables(Queue> cars) {
+ var x = cars.poll();
+ var y = cars.poll();
+ var z = cars.poll();
+ return x;
+ }
+
+ static Car> removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(Queue> cars) {
+ var car = cars.poll();
+ var _ = cars.poll();
+ var _ = cars.poll();
+ return car;
+ }
+
+ static void handleCarExceptionWithNamedVariables(Car> car) {
+ try {
+ someOperationThatFails(car);
+ } catch (IllegalStateException ex) {
+ System.out.println("Got an illegal state exception for: " + car.name());
+ } catch (RuntimeException ex) {
+ System.out.println("Got a runtime exception!");
+ }
+ }
+
+ static void handleCarExceptionWithUnnamedVariables(Car> car) {
+ try {
+ someOperationThatFails(car);
+ } catch (IllegalStateException | NumberFormatException _) {
+ System.out.println("Got an illegal state exception for: " + car.name());
+ } catch (RuntimeException _) {
+ System.out.println("Got a runtime exception!");
+ }
+ }
+
+ static void obtainTransactionAndUpdateCarWithNamedVariables(Car> car) {
+ try (var transaction = new Transaction()) {
+ updateCar(car);
+ }
+ }
+
+ static void obtainTransactionAndUpdateCarWithUnnamedVariables(Car> car) {
+ try (var _ = new Transaction()) {
+ updateCar(car);
+ }
+ }
+
+ static void updateCar(Car> car) {
+ // Some update logic
+ System.out.println("Car updated!");
+ }
+
+ static Map>> getCarsByFirstLetterWithNamedVariables(List> cars) {
+ Map>> carMap = new HashMap<>();
+ cars.forEach(car ->
+ carMap.computeIfAbsent(car.name().substring(0, 1), firstLetter -> new ArrayList<>()).add(car)
+ );
+ return carMap;
+ }
+
+ static Map>> getCarsByFirstLetterWithUnnamedVariables(List> cars) {
+ Map>> carMap = new HashMap<>();
+ cars.forEach(car ->
+ carMap.computeIfAbsent(car.name().substring(0, 1), _ -> new ArrayList<>()).add(car)
+ );
+ return carMap;
+ }
+
+ private static void someOperationThatFails(Car> car) {
+ throw new IllegalStateException("Triggered exception for: " + car.name());
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java
new file mode 100644
index 0000000000..bf0e2c96c2
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java
@@ -0,0 +1,3 @@
+void main() {
+ System.out.println("Hello, World!");
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java
new file mode 100644
index 0000000000..827be7c788
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java
@@ -0,0 +1,7 @@
+package com.baeldung.unnamedclasses;
+
+public class HelloWorldChild extends HelloWorldSuper {
+ void main() {
+ System.out.println("Hello, World!");
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java
new file mode 100644
index 0000000000..59c88716a4
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java
@@ -0,0 +1,7 @@
+package com.baeldung.unnamedclasses;
+
+public class HelloWorldSuper {
+ public static void main(String[] args) {
+ System.out.println("Hello from the superclass");
+ }
+}
diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java
new file mode 100644
index 0000000000..698516544e
--- /dev/null
+++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java
@@ -0,0 +1,6 @@
+private String getMessage() {
+ return "Hello, World!";
+}
+void main() {
+ System.out.println(getMessage());
+}
diff --git a/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java
new file mode 100644
index 0000000000..b9917cab18
--- /dev/null
+++ b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java
@@ -0,0 +1,67 @@
+package com.baeldung.stringtemplates;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StringTemplatesUnitTest {
+
+ @Test
+ public void whenStringConcat_thenReturnComposedString() {
+ StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingPlus("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenStringBuffer_thenReturnComposedString() {
+ StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuffer("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenStringBuilder_thenReturnComposedString() {
+ StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuilder("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenStringFormatter_thenReturnComposedFormattedString() {
+ StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingFormatters("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenMessageFormatter_thenReturnComposedFormattedString() {
+ StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingMessageFormatter("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenUsingStringTemplateSTR_thenReturnInterpolatedString() {
+ StringTemplateExamples templateExamples = new StringTemplateExamples();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationUsingSTRProcessor("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenUsingMultilineStringTemplateSTR_thenReturnInterpolatedString() {
+ StringTemplateExamples templateExamples = new StringTemplateExamples();
+ Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlock("pleasant", "25", "Celsius"));
+ }
+
+ @Test
+ public void whenUsingExpressionSTR_thenReturnInterpolatedString() {
+ StringTemplateExamples templateExamples = new StringTemplateExamples();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithExpressions());
+ }
+
+ @Test
+ public void whenUsingExpressionRAW_thenReturnInterpolatedString() {
+ StringTemplateExamples templateExamples = new StringTemplateExamples();
+ Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithTemplates());
+ }
+
+ @Test
+ public void whenUsingExpressionFMT_thenReturnInterpolatedString() {
+ StringTemplateExamples templateExamples = new StringTemplateExamples();
+ Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25.86\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlockWithFMT("pleasant", 25.8636F, "Celsius"));
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java
new file mode 100644
index 0000000000..2acb83cdef
--- /dev/null
+++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java
@@ -0,0 +1,13 @@
+package com.baeldung.unnamed.variables;
+
+import java.util.List;
+
+class CarScenario {
+
+ protected final List> cars = List.of(
+ new Car<>("Mitsubishi", "blue", new GasEngine()),
+ new Car<>("Toyota", "red", new ElectricEngine()),
+ new Car<>("Jaguar", "white", new HybridEngine())
+ );
+
+}
diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java
new file mode 100644
index 0000000000..9d860a201a
--- /dev/null
+++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java
@@ -0,0 +1,44 @@
+package com.baeldung.unnamed.variables;
+
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithNamedPattern;
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithUnnamedPattern;
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithNamedPattern;
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndNamedPattern;
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndUnnamedPattern;
+import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithUnnamedPattern;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class UnnamedPatternsUnitTest extends CarScenario {
+
+ @Test
+ public void whenExtractingColorWithNamedPatterns_thenReturnBlue() {
+ assertEquals("blue", getObjectsColorWithNamedPattern(cars.get(0)));
+ }
+
+ @Test
+ public void whenExtractingColorWithUnnamedPatterns_thenReturnBlue() {
+ assertEquals("blue", getObjectsColorWithUnnamedPattern(cars.get(0)));
+ }
+
+ @Test
+ public void whenExtractingColorWithSwitchAndNamedPatterns_thenReturnBlue() {
+ assertEquals("blue", getObjectsColorWithSwitchAndNamedPattern(cars.get(0)));
+ }
+
+ @Test
+ public void whenExtractingColorWithSwitchAndUnnamedPatterns_thenReturnBlue() {
+ assertEquals("blue", getObjectsColorWithSwitchAndUnnamedPattern(cars.get(0)));
+ }
+
+ @Test
+ public void whenExtractingEngineTypeWithNamedPatterns_thenReturnGas() {
+ assertEquals("gas", getEngineTypeWithNamedPattern(cars.get(0)));
+ }
+
+ @Test
+ public void whenExtractingEngineTypeWithUnnamedPatterns_thenReturnGas() {
+ assertEquals("gas", getEngineTypeWithUnnamedPattern(cars.get(0)));
+ }
+}
diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java
new file mode 100644
index 0000000000..094879c277
--- /dev/null
+++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java
@@ -0,0 +1,93 @@
+package com.baeldung.unnamed.variables;
+
+import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithNamedVariable;
+import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithUnnamedVariable;
+import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithNamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithUnnamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithNamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithUnnamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithNamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithUnnamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithNamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables;
+import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithNamedVariable;
+import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithUnnamedVariable;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.LinkedList;
+
+import org.junit.jupiter.api.Test;
+
+public class UnnamedVariablesUnitTest extends CarScenario {
+
+ @Test
+ public void whenCountingCarsOverLimitWithNamedVariables_thenShouldReturnOne() {
+ assertEquals(1, countCarsOverLimitWithNamedVariable(cars, 2));
+ }
+
+ @Test
+ public void whenCountingCarsOverLimitWithUnnamedVariables_thenShouldReturnOne() {
+ assertEquals(1, countCarsOverLimitWithUnnamedVariable(cars, 2));
+ }
+
+ @Test
+ public void whenNotifyingCarsWithNamedVariables_thenShouldNotFail() {
+ assertDoesNotThrow(() -> sendNotificationToCarsWithNamedVariable(cars));
+ }
+
+ @Test
+ public void whenNotifyingCarsWithUnnamedVariables_thenShouldNotFail() {
+ assertDoesNotThrow(() -> sendNotificationToCarsWithUnnamedVariable(cars));
+ }
+
+ @Test
+ public void whenPollingCarsWithNamedVariables_thenReturnFirstOneAndEmptyQueue() {
+ var carQueue = new LinkedList<>(cars);
+ assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithNamedVariables(carQueue).name());
+ assertEquals(0, carQueue.size());
+ }
+
+ @Test
+ public void whenPollingCarsWithUnnamedVariables_thenReturnFirstOneAndEmptyQueue() {
+ var carQueue = new LinkedList<>(cars);
+ assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(carQueue).name());
+ assertEquals(0, carQueue.size());
+ }
+
+ @Test
+ public void whenHandlingExceptionWithNamedVariables_thenNoExceptionIsThrown() {
+ assertDoesNotThrow(() -> handleCarExceptionWithNamedVariables(cars.get(0)));
+ }
+
+ @Test
+ public void whenHandlingExceptionWithUnnamedVariables_thenNoExceptionIsThrown() {
+ assertDoesNotThrow(() -> handleCarExceptionWithUnnamedVariables(cars.get(0)));
+ }
+
+ @Test
+ public void whenHandlingTransactionUpdateWithNamedVariables_thenNoExceptionIsThrown() {
+ assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithNamedVariables(cars.get(0)));
+ }
+
+ @Test
+ public void whenHandlingTransactionUpdateWithUnnamedVariables_thenNoExceptionIsThrown() {
+ assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithUnnamedVariables(cars.get(0)));
+ }
+
+ @Test
+ public void whenGettingCarsByFirstLetterWithNamedVariables_thenHaveThreeKeys() {
+ var carsByLetter = getCarsByFirstLetterWithNamedVariables(cars);
+ assertEquals(1, carsByLetter.get("M").size());
+ assertEquals(1, carsByLetter.get("T").size());
+ assertEquals(1, carsByLetter.get("J").size());
+ }
+
+ @Test
+ public void whenGettingCarsByFirstLetterWithUnnamedVariables_thenHaveThreeKeys() {
+ var carsByLetter = getCarsByFirstLetterWithUnnamedVariables(cars);
+ assertEquals(1, carsByLetter.get("M").size());
+ assertEquals(1, carsByLetter.get("T").size());
+ assertEquals(1, carsByLetter.get("J").size());
+ }
+}
diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java
index be43fb609a..d1bd77776a 100644
--- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java
+++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java
@@ -3,9 +3,11 @@ package com.baeldung.dateapi;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Duration;
import java.time.Instant;
+import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
@@ -19,7 +21,7 @@ public class JavaDurationUnitTest {
LocalTime finalTime = initialTime.plus(Duration.ofSeconds(30));
long seconds = Duration.between(initialTime, finalTime)
- .getSeconds();
+ .getSeconds();
assertThat(seconds).isEqualTo(30);
}
@@ -34,6 +36,22 @@ public class JavaDurationUnitTest {
assertThat(seconds).isEqualTo(30);
}
+ @Test
+ public void givenADuration_whenCallingisZeroAndisNegative_thenGetExpectedResult() {
+ LocalDateTime start = LocalDateTime.parse("2020-01-01T08:00:00");
+ LocalDateTime end = LocalDateTime.parse("2020-01-01T12:00:00");
+ assertFalse(Duration.between(start, end)
+ .isNegative());
+ assertTrue(Duration.between(end, start)
+ .isNegative());
+
+ LocalDateTime theTime = LocalDateTime.parse("2023-09-09T08:00:00");
+ assertTrue(Duration.between(theTime, theTime)
+ .isZero());
+ assertFalse(Duration.between(theTime, theTime)
+ .isNegative());
+ }
+
@Test
public void test2() {
Instant start = Instant.parse("2017-10-03T10:15:30.00Z");
@@ -53,17 +71,17 @@ public class JavaDurationUnitTest {
assertEquals(1, fromMinutes.toHours());
assertEquals(120, duration.plusSeconds(60)
- .getSeconds());
+ .getSeconds());
assertEquals(30, duration.minusSeconds(30)
- .getSeconds());
+ .getSeconds());
assertEquals(120, duration.plus(60, ChronoUnit.SECONDS)
- .getSeconds());
+ .getSeconds());
assertEquals(30, duration.minus(30, ChronoUnit.SECONDS)
- .getSeconds());
+ .getSeconds());
Duration fromChar1 = Duration.parse("P1DT1H10M10.5S");
Duration fromChar2 = Duration.parse("PT10M");
}
-}
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-9-streams/README.md b/core-java-modules/core-java-9-streams/README.md
index 0ad8500689..d9663e0858 100644
--- a/core-java-modules/core-java-9-streams/README.md
+++ b/core-java-modules/core-java-9-streams/README.md
@@ -4,3 +4,4 @@ This module contains articles about Java 9 streams
### Relevant Articles:
- [How to Break from Java Stream forEach](https://www.baeldung.com/java-break-stream-foreach)
+- [Creating Stream of Regex Matches](https://www.baeldung.com/java-stream-regex-matches)
diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md
index 0af77980af..d8b0d126a1 100644
--- a/core-java-modules/core-java-arrays-guides/README.md
+++ b/core-java-modules/core-java-arrays-guides/README.md
@@ -9,3 +9,4 @@ This module contains complete guides about arrays in Java
- [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception)
- [Creating a Generic Array in Java](https://www.baeldung.com/java-generic-array)
- [Maximum Size of Java Arrays](https://www.baeldung.com/java-arrays-max-size)
+- [Merge Two Arrays and Remove Duplicates in Java](https://www.baeldung.com/java-merge-two-arrays-delete-duplicates)
diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/README.md b/core-java-modules/core-java-arrays-operations-advanced-2/README.md
new file mode 100644
index 0000000000..17ffa2562d
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced-2/README.md
@@ -0,0 +1,2 @@
+## Relevant Articles
+- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item)
diff --git a/core-java-modules/core-java-arrays-operations-advanced/README.md b/core-java-modules/core-java-arrays-operations-advanced/README.md
index 0647d89d16..b379958f37 100644
--- a/core-java-modules/core-java-arrays-operations-advanced/README.md
+++ b/core-java-modules/core-java-arrays-operations-advanced/README.md
@@ -14,4 +14,3 @@ This module contains articles about advanced operations on arrays in Java. They
- [Slicing Arrays in Java](https://www.baeldung.com/java-slicing-arrays)
- [Combining Two or More Byte Arrays](https://www.baeldung.com/java-concatenate-byte-arrays)
- [Calculating the Sum of Two Arrays in Java](https://www.baeldung.com/java-sum-arrays-element-wise)
-- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item)
diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java
new file mode 100644
index 0000000000..7621e85762
--- /dev/null
+++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java
@@ -0,0 +1,29 @@
+package com.baeldung.incrementchar;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+class IncrementCharUnitTest {
+ @Test
+ void whenUsingForLoop_thenGenerateCharacters(){
+ final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
+ List characters = new ArrayList<>();
+ for (char character = 'A'; character <= 'Z'; character++) {
+ characters.add(character);
+ }
+ Assertions.assertEquals(characters, allCapitalCharacters);
+ }
+
+ @Test
+ void whenUsingStreams_thenGenerateCharacters() {
+ final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
+ final List characters = IntStream.rangeClosed('A', 'Z').mapToObj(c -> (char) c).collect(Collectors.toList());
+ Assertions.assertEquals(characters, allCapitalCharacters);
+ }
+}
diff --git a/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java
new file mode 100644
index 0000000000..86982486fa
--- /dev/null
+++ b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java
@@ -0,0 +1,126 @@
+package com.baeldung.skippingfirstelement;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class SkipFirstElementExample {
+
+ private final List stringList = new ArrayList<>();
+ private final Set stringSet = new HashSet<>();
+ private final Map stringMap = new HashMap<>();
+
+ public SkipFirstElementExample() {
+ // Initializing a List
+ stringList.add("Monday");
+ stringList.add("Tuesday");
+ stringList.add("Wednesday");
+ stringList.add("Thursday");
+ stringList.add("Friday");
+ stringList.add("Saturday");
+ stringList.add("Sunday");
+ // Initializing a Set
+ stringSet.add("Monday");
+ stringSet.add("Tuesday");
+ stringSet.add("Wednesday");
+ stringSet.add("Thursday");
+ stringSet.add("Friday");
+ stringSet.add("Saturday");
+ stringSet.add("Sunday");
+ // Initializing a Map
+ stringMap.put("Monday", "The day when coffee is a life support system.");
+ stringMap.put("Tuesday", "The day you realize that Monday's optimism was a lie.");
+ stringMap.put("Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day.");
+ stringMap.put("Thursday", "The day that says, 'Hold my beer, Friday is coming!'");
+ stringMap.put("Friday", "The golden child of the weekdays. The superhero of the workweek.");
+ stringMap.put("Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'");
+ stringMap.put("Sunday", "The day before you have to adult again.");
+ }
+
+ void skippingFirstElementInListWithForLoop(List stringList) {
+ for (int i = 1; i < stringList.size(); i++) {
+ process(stringList.get(i));
+ }
+ }
+
+ void skippingFirstElementInListWithWhileLoop(List stringList) {
+ final Iterator iterator = stringList.iterator();
+ if (iterator.hasNext()) {
+ iterator.next();
+ }
+ while (iterator.hasNext()) {
+ process(iterator.next());
+ }
+ }
+
+ void skippingFirstElementInSetWithWhileLoop(Set stringSet) {
+ final Iterator iterator = stringSet.iterator();
+ if (iterator.hasNext()) {
+ iterator.next();
+ }
+ while (iterator.hasNext()) {
+ process(iterator.next());
+ }
+ }
+
+ void skippingFirstElementInListWithWhileLoopStoringFirstElement(List stringList) {
+ final Iterator iterator = stringList.iterator();
+ String firstElement = null;
+ if (iterator.hasNext()) {
+ firstElement = iterator.next();
+ }
+ while (iterator.hasNext()) {
+ process(iterator.next());
+ // additional logic using fistElement
+ }
+ }
+
+ void skippingFirstElementInMapWithStreamSkip(Map stringMap) {
+ stringMap.entrySet().stream().skip(1).forEach(this::process);
+ }
+
+ void skippingFirstElementInListWithSubList(List stringList) {
+ for (final String element : stringList.subList(1, stringList.size())) {
+ process(element);
+ }
+ }
+
+ void skippingFirstElementInListWithForLoopWithAdditionalCheck(List stringList) {
+ for (int i = 0; i < stringList.size(); i++) {
+ if (i == 0) {
+ // do something else
+ } else {
+ process(stringList.get(i));
+ }
+ }
+ }
+
+ void skippingFirstElementInListWithWhileLoopWithCounter(List stringList) {
+ int counter = 0;
+ while (counter < stringList.size()) {
+ if (counter != 0) {
+ process(stringList.get(counter));
+ }
+ ++counter;
+ }
+ }
+
+ void skippingFirstElementInListWithReduce(List stringList) {
+ stringList.stream().reduce((skip, element) -> {
+ process(element);
+ return element;
+ });
+ }
+
+ protected void process(String string) {
+ System.out.println(string);
+ }
+ protected void process(Entry mapEntry) {
+ System.out.println(mapEntry);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java
new file mode 100644
index 0000000000..9821b22ac7
--- /dev/null
+++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java
@@ -0,0 +1,122 @@
+package com.baeldung.skippingfirstelement;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.condition.EnabledForJreRange;
+import org.junit.jupiter.api.condition.JRE;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+@EnabledForJreRange(min = JRE.JAVA_9)
+class SkipFirstElementExampleUnitTest {
+
+ private static TestableSkipFirstElement testableSkip = new TestableSkipFirstElement();
+
+ @BeforeEach
+ void setup() {
+ testableSkip.reset();
+ }
+
+ private static Stream listProvider() {
+ return Stream.of(
+ Arguments.of(
+ List.of("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"),
+ List.of("Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
+ );
+ }
+
+ private static Stream mapProvider() {
+ return Stream.of(
+ Arguments.of(
+ Map.of(
+ "Monday", "The day when coffee is a life support system.",
+ "Tuesday", "The day you realize that Monday's optimism was a lie.",
+ "Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day.",
+ "Thursday", "The day that says, 'Hold my beer, Friday is coming!'",
+ "Friday", "The golden child of the weekdays. The superhero of the workweek.",
+ "Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'",
+ "Sunday", "The day before you have to adult again."
+ )
+ )
+ );
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithForLoop(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithForLoop(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithWhileLoop(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithWhileLoop(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInSetWithWhileLoop(List input) {
+ testableSkip.skippingFirstElementInSetWithWhileLoop(new HashSet<>(input));
+ Set> actual = new HashSet<>(testableSkip.getResult());
+ assertEquals(actual.size(), input.size() - 1);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithWhileLoopStoringFirstElement(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithWhileLoopStoringFirstElement(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("mapProvider")
+ void skippingFirstElementInMapWithStreamSkip(Map input) {
+ testableSkip.skippingFirstElementInMapWithStreamSkip(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual.size(), input.size() - 1);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithSubList(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithSubList(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithForLoopWithAdditionalCheck(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithForLoopWithAdditionalCheck(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithWhileLoopWithCounter(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithWhileLoopWithCounter(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+
+ @ParameterizedTest
+ @MethodSource("listProvider")
+ void skippingFirstElementInListWithReduce(List input, List expected) {
+ testableSkip.skippingFirstElementInListWithReduce(input);
+ List> actual = testableSkip.getResult();
+ assertEquals(actual, expected);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java
new file mode 100644
index 0000000000..0e2f340485
--- /dev/null
+++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java
@@ -0,0 +1,10 @@
+package com.baeldung.skippingfirstelement;
+
+import java.util.List;
+
+public interface TestableSkip {
+
+ void reset();
+
+ List> getResult();
+}
diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java
new file mode 100644
index 0000000000..99facb73ad
--- /dev/null
+++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java
@@ -0,0 +1,37 @@
+package com.baeldung.skippingfirstelement;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
+public class TestableSkipFirstElement extends SkipFirstElementExample implements TestableSkip {
+
+
+ private List processedList = new ArrayList<>();
+ private List> processedEntryList = new ArrayList<>();
+
+ @Override
+ public void process(String string) {
+ processedList.add(string);
+ }
+
+ @Override
+ public void process(Entry stringEntry) {
+ processedEntryList.add(stringEntry);
+ }
+
+ @Override
+ public void reset() {
+ processedList.clear();
+ processedEntryList.clear();
+ }
+
+ @Override
+ public List> getResult() {
+ if (!processedList.isEmpty())
+ return processedList;
+ return processedEntryList;
+ }
+
+
+}
diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md
new file mode 100644
index 0000000000..dbf5c47edb
--- /dev/null
+++ b/core-java-modules/core-java-collections-array-list-2/README.md
@@ -0,0 +1,6 @@
+## Core Java Collections ArrayList
+
+This module contains articles about the Java ArrayList collection
+
+### Relevant Articles:
+- [Create an ArrayList with Multiple Object Types](https://www.baeldung.com/arraylist-with-multiple-object-types)
diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml
new file mode 100644
index 0000000000..042f6e5bb5
--- /dev/null
+++ b/core-java-modules/core-java-collections-array-list-2/pom.xml
@@ -0,0 +1,32 @@
+
+ 4.0.0
+ core-java-collections-array-list-2
+ core-java-collections-array-list-2
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ ${maven-compiler-plugin.target}
+
+
+
+
+
+
+ 17
+ 17
+
+
diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java
new file mode 100644
index 0000000000..5315147dff
--- /dev/null
+++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java
@@ -0,0 +1,51 @@
+package com.baeldung.list.multipleobjecttypes;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.function.Predicate;
+
+public class AlternativeMultipeTypeList {
+
+ public static void main(String[] args) {
+ // List of Parent Class
+ ArrayList myList = new ArrayList<>();
+ myList.add(1.2);
+ myList.add(2);
+ myList.add(-3.5);
+
+ // List of Interface type
+ ArrayList