0 votes
22 views

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

in Education by (51.6k points)

1 Answer

0 votes

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 (51.6k points)

Related questions

0 votes
1 answer 8 views
0 votes
1 answer 11 views
0 votes
1 answer 8 views
0 votes
1 answer 15 views
0 votes
1 answer 13 views
0 votes
1 answer 17 views
0 votes
1 answer 11 views
0 votes
1 answer 13 views
0 votes
1 answer 50 views
0 votes
1 answer 14 views
0 votes
1 answer 34 views
0 votes
1 answer 14 views
0 votes
1 answer 12 views
0 votes
1 answer 12 views
...