Java 8 program to perform cube on list element and filters numbers greater 60.

There are following way to perform cube on list element and filters numbers greater 60.

Using map and filter method :-

  • First convert Arrays to list using Arrays.asList method
  • Now get the Stream data from List using arrayList.stream() method
  • From map method we convert each list of number in cube(r->r*r*r)
  • In filter they will check which cube number is greater than 60.
  • Print the numbers from forEach() 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<Integer> l = Arrays.asList(5, 3, 7, 9, 1, 2, 4);
		l.stream().map(r -> r * r * r).filter(i -> i > 60).forEach(System.out::println);
	    	}
		}
				
			

Output :-
125
343
729
64