how to add different types of objects in arraylist in java


Post a Comment:





Showing 0 Comments:
Be the first to comment!

External ressources related to how to add different types of objects in arraylist in java

ArrayList with different Object Types - Java Learning Academy
http://www.javalearningacademy.com/arraylist-different-object-types/

Keeping different types of objects in the same ArrayList object could be done by using Object generic type. The idea here is to allow ArrayList to take any Object then check the actual type at the time of retrieving it. The following code explains this: [

Add multiple items to ArrayList in Java - HowToDoInJava
https://howtodoinjava.com/java/collections/arraylist/add-multiple-elements-arraylist/

2. Add only selected items to arraylist. This method uses Java 8 stream API. We create a stream of elements from first list, add filter to get the desired elements only, and then collect filtered elements to another list.

java - Create an ArrayList with multiple object types ...
https://stackoverflow.com/questions/19602601/create-an-arraylist-with-multiple-object-types

As the return type of ArrayList is object, you can add any type of data to ArrayList but it is not a good practice to use ArrayList because there is unnecessary ...