Restructuring to new module
Restructuring to new module
This commit is contained in:
parent
5159e8ab67
commit
da0beaeee0
@ -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://drafts.baeldung.com/create-an-arraylist-with-multiple-object-types/)
|
38
core-java-modules/core-java-collections-array-list-2/pom.xml
Normal file
38
core-java-modules/core-java-collections-array-list-2/pom.xml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>core-java-collections-array-list-2</artifactId>
|
||||||
|
<name>core-java-collections-array-list-2</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.core-java-modules</groupId>
|
||||||
|
<artifactId>core-java-modules</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>${maven-compiler-plugin.source}</source>
|
||||||
|
<target>${maven-compiler-plugin.target}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${surefire.plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<argLine>
|
||||||
|
--add-opens java.base/java.util=ALL-UNNAMED
|
||||||
|
</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<properties>
|
||||||
|
<maven-compiler-plugin.source>16</maven-compiler-plugin.source>
|
||||||
|
<maven-compiler-plugin.target>16</maven-compiler-plugin.target>
|
||||||
|
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -1,5 +1,7 @@
|
|||||||
package com.baeldung.list.multiple.objecttypes;
|
package com.baeldung.list.multiple.objecttypes;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -7,27 +9,32 @@ import java.util.List;
|
|||||||
public class MultipleObjectTypeArrayList {
|
public class MultipleObjectTypeArrayList {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
ArrayList<Object> multiTypeList = new ArrayList<>();
|
ArrayList<Object> multiTypeList = new ArrayList<>();
|
||||||
|
|
||||||
multiTypeList.add(Integer.valueOf(10));
|
multiTypeList.add(Integer.valueOf(10));
|
||||||
multiTypeList.add(Double.valueOf(11.5));
|
multiTypeList.add(Double.valueOf(11.5));
|
||||||
multiTypeList.add("String Data");
|
multiTypeList.add("String Data");
|
||||||
multiTypeList.add(Arrays.asList(1, 2, 3));
|
multiTypeList.add(Arrays.asList(1, 2, 3));
|
||||||
multiTypeList.add(new CustomObject("Class Data"));
|
multiTypeList.add(new CustomObject("Class Data"));
|
||||||
|
multiTypeList.add(BigInteger.valueOf(123456789));
|
||||||
|
multiTypeList.add(LocalDate.of(2023, 9, 19));
|
||||||
|
|
||||||
for (Object dataObj : multiTypeList) {
|
for (Object dataObj : multiTypeList) {
|
||||||
if (dataObj instanceof Integer intData)
|
if (dataObj instanceof Integer intData)
|
||||||
System.out.println("Integer Data : " + intData);
|
System.out.println("Integer Data : " + intData);
|
||||||
if (dataObj instanceof Double doubleData)
|
else if (dataObj instanceof Double doubleData)
|
||||||
System.out.println("Double Data : " + doubleData);
|
System.out.println("Double Data : " + doubleData);
|
||||||
if (dataObj instanceof String stringData)
|
else if (dataObj instanceof String stringData)
|
||||||
System.out.println("String Data : " + stringData);
|
System.out.println("String Data : " + stringData);
|
||||||
if (dataObj instanceof List<?> intList)
|
else if (dataObj instanceof List<?> intList)
|
||||||
System.out.println("List Data : " + intList);
|
System.out.println("List Data : " + intList);
|
||||||
if (dataObj instanceof CustomObject customObj)
|
else if (dataObj instanceof CustomObject customObj)
|
||||||
System.out.println("CustomObject Data : " + customObj.getClassData());
|
System.out.println("CustomObject Data : " + customObj.getClassData());
|
||||||
|
else if (dataObj instanceof BigInteger bigIntData)
|
||||||
|
System.out.println("BigInteger Data : " + bigIntData);
|
||||||
|
else if (dataObj instanceof LocalDate localDate)
|
||||||
|
System.out.println("LocalDate Data : " + localDate.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -177,6 +177,7 @@
|
|||||||
<module>core-java-collections-maps-6</module>
|
<module>core-java-collections-maps-6</module>
|
||||||
<module>core-java-records</module>
|
<module>core-java-records</module>
|
||||||
<module>core-java-9-jigsaw</module>
|
<module>core-java-9-jigsaw</module>
|
||||||
|
<module>core-java-collections-array-list-2</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user