Java 8 Program to Find Cube of List Elements and Filter Number Greater Than 60.

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 map() 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 :-

  • First convert array to list using Arrays.asList() method
  • Now convert the list into a stream using stream()
  • Use map() to calculate cube(r->r*r*r)
  • Use filter() to check values greater than 60.
  • Use forEach() to print the result.
				
					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<Integer> 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