- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to get the reverse of an Integer array with Lambda Expressions
Let us first declare and initialize an Integer array:
Integer[] arr = {20, 50, 75, 100, 120, 150, 170, 200};
To find the reverse of the Integer array with Lambda, use sort and the Lamda:
Arrays.sort(arr, (Integer one, Integer two) -> { return (two- one); });
The following is an example to reverse an Integer array with Lambda Expressions:
Example
import java.util.Arrays; public class Demo { public static void main(String[] args) { Integer[] arr = {20, 50, 75, 100, 120, 150, 170, 200}; System.out.println("Integer Array elements..."); for (int res : arr) { System.out.println(res); } Arrays.sort(arr, (Integer one, Integer two) -> { return (two- one); }); System.out.println("Reverse of Array elements..."); System.out.println(Arrays.toString(arr)); } }
Output
Integer Array elements... 20 50 75 100 120 150 170 200 Reverse of Array elements... [200, 170, 150, 120, 100, 75, 50, 20]
Advertisements
To Continue Learning Please Login
Login with Google