Java Lambda - Exercises, Practice, Solution
Java Lambda [25 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
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. Write a Java program to implement a lambda expression to find the sum of two integers.
2. Write a Java program to implement a lambda expression to check if a given string is empty.
3. Write a Java program to implement a lambda expression to convert a list of strings to uppercase and lowercase.
4. Write a Java program to implement a lambda expression to filter out even and odd numbers from a list of integers.
5. Write a Java program to implement a lambda expression to sort a list of strings in alphabetical order.
6. Write a Java program to implement a lambda expression to find the average of a list of doubles.
7. Write a Java program to implement a lambda expression to remove duplicates from a list of integers.
8. Write a lambda expression to implement a lambda expression to calculate the factorial of a given number.
9. Write a Java program to implement a lambda expression to create a lambda expression to check if a number is prime.
10. Write a Java program to implement a lambda expression to concatenate two strings.
11. Write a Java program to implement a lambda expression to find the maximum and minimum values in a list of integers.
12. Write a Java program to create a lambda expression to multiply and sum all elements in a list of integers.
13. Write a Java program to implement a lambda expression to count words in a sentence.
14. Write a Java program to implement a lambda expression to check if a given string is a palindrome.
15. Write a Java program to implement a lambda expression to calculate the sum of squares of all odd and even numbers in a list.
16. Write a Java program to implement a lambda expression to check if a list of strings contains a specific word.
17. Write a Java program to implement a lambda expression to find the length of the longest and smallest string in a list.
18. Write a Java program to implement a lambda expression to check if a given number is a perfect square.
19. Write a Java program to implement a lambda expression to find the second largest and smallest element in an array.
20. Write a Java program to implement a lambda expression to sort a list of objects based on a specific attribute.
21. Write a Java program to implement a lambda expression to calculate the sum of all prime numbers in a given range.
22. Write a Java program to implement a lambda expression to check if a list of strings are all uppercase or all lowercase or mixedcase.
23. Write a Java program to implement a lambda expression to find the average length of strings in a list.
24. Write a Java program to implement a lambda expression to find the largest prime factor of a given number.
25. Write a Java program to implement a lambda expression to convert an integer to their corresponding binary representation.
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.
Java: Tips of the Day
How do I remove repeated elements from ArrayList?
If you don't want duplicates in a Collection, you should consider why you're using a Collection that allows duplicates. The easiest way to remove repeated elements is to add the contents to a Set (which will not allow duplicates) and then add the Set back to the ArrayList:
Set<String> set = new HashSet<>(yourList); yourList.clear(); yourList.addAll(set);
Of course, this destroys the ordering of the elements in the ArrayList.
Ref: https://bit.ly/3bYIjNC
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook