0
How will you print unique squares of numbers in Java 8?

Open 1 Answers 52 Views Education

How will you print unique squares of numbers in Java 8?

1 Answer

0

How will you print unique squares of numbers in Java 8?

The following code segment prints unique squares of numbers using map.

List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);

//get list of unique squares

List<Integer> squaresList = numbers.stream().map( i -> i*i).distinct().collect(Collectors.toList());

by (53.7k points)
...