简单易用的数组排序(升序、降序)
2016-05-27 11:30
309 查看
import java.util.Arrays; import java.util.Comparator; /** * Created by idea on 2016/5/27. * @Author:我就是你的小星星 */
@SuppressWarnings("all") public class Sort { public static void main(String[] args) { Integer [] nums = {1,2,5,3,8}; positiveNums(nums); reverseNums(nums); } /** * 数组正序排列 * @param nums 数组参数 */ public static void positiveNums(Integer [] nums){ Arrays.sort(nums); System.out.println(nums); } /** * 数组倒序排列 * @param nums 数组参数 */ public static void reverseNums(Integer [] nums){ Arrays.sort(nums, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return -(o1-o2); } }); System.out.println(Arrays.toString(nums)); } }对本文章有疑问者可以向博主提出,如需转载请说明出处。
相关文章推荐
- IntelliJ IDEA & Android Studio的调整优化
- Intellij IDEA控制台乱码解决方法
- idea中切换svn地址不起作用
- 使用Ant构建SSH项目(Intellij IDEA版)
- idea常用设置
- Intellij idea使用Git@Osc发布项目(干货)
- IntelliJ IDEA使用Application Server开发普通Java Web项目
- IntelliJ IDEA使用Maven快速开发Java Web项目,并添加JFinal依赖
- 在线安装 IntelliJ IDEA的 golang 插件
- Intellij IDEA整理
- 为了响应大家对IDEA 12的支持,特奉上一个解决中文字体问题的好东东
- IntelliJ Idea 常用快捷键列表
- 给大家推荐一个IDEA快捷键等的设置
- 使用IntelliJ IDEA 14和Maven创建java web项目
- IntelliJ Idea 常用快捷键列表
- idea代码调试debug篇
- Intellij idea几个设置
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- 安装eclipse,jdk安装好了,环境变量也配置好了,但是eclipse还是打不开
- IDEA上的mybatis绑定错误