w3resource

Java Lambda - Exercises, Practice, Solution


This resource offers a total of 125 Java Lambda problems for practice. It includes 25 main exercises, each accompanied by solutions, detailed explanations, and four related problems.

[An Editor is available at the bottom of the page to write and execute the scripts.]

Java 8 introduces several new language features designed to make it easier to write such blocks of code-the key feature being lambda expressions, also colloquially referred to as closures or anonymous methods. A lambda expression is just a shorter way of writing an implementation of a method for later execution.

1. Sum two integers using lambda expression

Write a Java program to implement a lambda expression to find the sum of two integers.

Click me to see the solution

2. Check if a string is empty using lambda

Write a Java program to implement a lambda expression to check if a given string is empty.

Click me to see the solution

3. Convert strings to upper/lowercase using lambda

Write a Java program to implement a lambda expression to convert a list of strings to uppercase and lowercase.

Click me to see the solution

4. Filter even and odd numbers with lambda

Write a Java program to implement a lambda expression to filter out even and odd numbers from a list of integers.

Click me to see the solution

5. Sort strings alphabetically using lambda

Write a Java program to implement a lambda expression to sort a list of strings in alphabetical order.

Click me to see the solution

6. Find average of doubles using lambda

Write a Java program to implement a lambda expression to find the average of a list of doubles.

Click me to see the solution

7. Remove integer duplicates using lambda

Write a Java program to implement a lambda expression to remove duplicates from a list of integers.

Click me to see the solution

8. Calculate factorial using lambda expression

Write a lambda expression to implement a lambda expression to calculate the factorial of a given number.

Click me to see the solution

9. Check if number is prime using lambda

Write a Java program to implement a lambda expression to create a lambda expression to check if a number is prime.

Click me to see the solution

10. Concatenate two strings using lambda

Write a Java program to implement a lambda expression to concatenate two strings.

Click me to see the solution

11. Find max and min in list using lambda

Write a Java program to implement a lambda expression to find the maximum and minimum values in a list of integers.

Click me to see the solution

12. Multiply and sum list elements using lambda

Write a Java program to create a lambda expression to multiply and sum all elements in a list of integers.

Click me to see the solution

13. Count words in sentence with lambda

Write a Java program to implement a lambda expression to count words in a sentence.

Click me to see the solution

14. Check if string is palindrome using lambda

Write a Java program to implement a lambda expression to check if a given string is a palindrome.

Click me to see the solution

15. Sum squares of odd/even numbers using lambda

Write a Java program to implement a lambda expression to calculate the sum of squares of all odd and even numbers in a list.

Click me to see the solution

16. Check if word exists in list using lambda

Write a Java program to implement a lambda expression to check if a list of strings contains a specific word.

Click me to see the solution

17. Find longest and shortest string using lambda

Write a Java program to implement a lambda expression to find the length of the longest and smallest string in a list.

Click me to see the solution

18. Check if number is a perfect square using lambda

Write a Java program to implement a lambda expression to check if a given number is a perfect square.

Click me to see the solution

19. Find 2nd largest/smallest in array using lambda

Write a Java program to implement a lambda expression to find the second largest and smallest element in an array.

Click me to see the solution

20. Sort objects by attribute using lambda

Write a Java program to implement a lambda expression to sort a list of objects based on a specific attribute.

Click me to see the solution

21. Sum all primes in range using lambda

Write a Java program to implement a lambda expression to calculate the sum of all prime numbers in a given range.

Click me to see the solution

22. Check case of strings in list using lambda

Write a Java program to implement a lambda expression to check if a list of strings are all uppercase or all lowercase or mixedcase.

Click me to see the solution

23. Find average string length using lambda

Write a Java program to implement a lambda expression to find the average length of strings in a list.

Click me to see the solution

24. Find largest prime factor using lambda

Write a Java program to implement a lambda expression to find the largest prime factor of a given number.

Click me to see the solution

25. Convert integer to binary using lambda

Write a Java program to implement a lambda expression to convert an integer to their corresponding binary representation.

Click me to see the solution

More to Come !

* To run the code mouse over on Result panel and click on 'RERUN' button.*

Java Code Editor


Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.