in Education by

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

1 Answer

0 votes
by

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());

Related questions

0 votes
    How will you print 10 random numbers in a sorted order in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print 10 random numbers in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print 10 random numbers using forEach of java 8 ?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you print count of empty strings in Java 8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you get the sum of all numbers present in a list using Java 8 in Java8?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    A child's game has 8 triangles of which 3 are blue and rest are red, and 10 squares of which 6 are blue ... iv) triangle of red colour Select the correct answer from above options...
asked Nov 21, 2021 in Education by JackTerrance
0 votes
    How will you get the highest number present in a list using Java 8...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    How will you sort a list of string using Java 8 lambda expression?...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    >>> list(range(0, -9,-1)) will print [-1, -2, -3, -4,-5, -6, -7, -8) [0,-1, -2, -3, -4,-5, -6, -7, -8 ... [0,-1, -2, -3, -4,-5, -6, -7] Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the numbers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    WAP in java to input 3 numbers from user and print the largest no. among them using nested if. Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    WAP in java to input 2 numbers from user and print their difference (Always Positive). Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Write a program in Java to print all palindromic numbers between 150-250. Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    can anyone please help me out for this question Write a program to create two threads, so one thread will print ... between 11 to 20. Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    can anyone please help me out for this question Write a program to create two threads, so one thread will print ... between 11 to 20. Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
...