In Java 8,Program to Find Cube of List Elements and Filter Number Greater Than 60. here Stream API provides a simple and efficient way to process collections. Using map() and filter() methods, we can easily perform transformations and filtering operations on data.
In this example, we will calculate the cube of each element in a list and display only those values that are greater than 60.
Using map() and filter() method :-
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
List list = Arrays.asList(5, 3, 7, 9, 1, 2, 4);
list.stream().map(r -> r * r * r).filter(i -> i > 60).forEach(System.out::println);
}
}
Output :-
125
343
729
64