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]
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短