Using java 8
, specifically lambda expression
, you can do it simply like the below example:
myProducts.stream().filter(prod -> prod.price>10).collect(Collectors.toList())
where for each product
inside myProducts
collection, if prod.price>10
, then add this product to the new filtered list.