Java程序使用Lambda表达式获得与Integer数组相反的结果
让我们首先声明并初始化一个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]
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿