重写Arrays中的sort方法,实现数组的降序排序
来源:互联网 发布:中万网络销售 编辑:程序博客网 时间:2024/06/10 09:10
package com.test;
import java.util.Arrays;
import java.util.Comparator;
public class ArraysSort {
public static void main(String args[]){
Integer[] arr={1,2,3,4,5,6};
Arrays.sort(arr, new Comparator<Object>(){
public int compare(Object arg0,Object arg1){
Integer a=(Integer)arg0;
Integer b=(Integer)arg1;
int temp=Integer.compare(a,b);
return -temp;
}
});
for(int a: arr){
System.out.println(a+"\t");
}
}
}
import java.util.Arrays;
import java.util.Comparator;
public class ArraysSort {
public static void main(String args[]){
Integer[] arr={1,2,3,4,5,6};
Arrays.sort(arr, new Comparator<Object>(){
public int compare(Object arg0,Object arg1){
Integer a=(Integer)arg0;
Integer b=(Integer)arg1;
int temp=Integer.compare(a,b);
return -temp;
}
});
for(int a: arr){
System.out.println(a+"\t");
}
}
}
0 0
- 重写Arrays中的sort方法,实现数组的降序排序
- 数组的排序,方法Arrays.sort(你创建的数组)
- 数组,vector的sort快速降序方法
- 数组排序 java.util.Arrays类的sort方法
- JAVA 中 Arrays.sort 中的排序的方法
- 数组排序Arrays.sort
- Arrays.sort数组排序
- Java的数组和list升序,降序,逆序函数Collections.sort和Arrays.sort的使用
- 利用Arrays.sort();方法对相应数组进行升序、降序排列
- 实现对数组的降序排序
- [Java]Arrays.sort() 数组排序
- Java数组排序Arrays.sort
- 数组排序Arrays.sort()
- java中数组排序arrays.sort方法应用
- js:数组重排序问题:如何使用sort()方法按数值的大小进行升序或降序排列
- Java数组排序Arrays.sort,以及Comparator接口的用法
- java数组排序Arrays.sort,以及Comparator接口的用法
- Java数组排序Arrays.sort,以及Comparator接口的用法
- 织梦添加文档自定义属性
- sql基础
- iOS8中使用CoreLocation定位
- Scrapy系列教程(3)------Spider(爬虫核心,定义链接关系和网页信息抽取)
- poj3260 The Fewest Coins
- 重写Arrays中的sort方法,实现数组的降序排序
- 公司
- Linux - 计划任务 [ at ]
- UE 高亮 一个或多个关键字的方法
- Java对象序列化原理以及Serializable接口
- Eclipse快捷键大全(转载)
- android preference介绍
- SecureCRT&SecureFX_v7.2.5_x86&x64_build_524 破解安装教程
- Two or more Web modules defined in the configuration have the same context root (/bms).