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: [
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.
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 ...
Post a Comment:
Showing 0 Comments: