Sometimes you have a mixed Collection in Java. A simple example is having a List<Number> , where the list may contain Integer, Float, Long and Double instances. How can you easily filter out the List<Integer> or the List<Double>? I will demonstrate how to do this with classic Java, using Pattern matching for instanceof in Java 16, and using two different approaches with Eclipse Collections. I have also added a preview solution using JDK 17 EA and Pattern Matching in Switch.

#Java 

Easiest How to Filtering a Java Collection by type
1.60 GEEK