让我们首先声明并初始化一个Integer数组:
Integer[] arr = {20, 50, 75, 100, 120, 150, 170, 200};
要查找带Lambda的Integer数组的逆函数,请使用sort和Lamda:
Arrays.sort(arr, (Integer one, Integer two) -> { return (two- one); });
以下是使用Lambda表达式反转Integer数组的示例:
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)); } }
输出结果
Integer Array elements... 20 50 75 100 120 150 170 200 Reverse of Array elements... [200, 170, 150, 120, 100, 75, 50, 20]