当前位置:网站首页>Sort method for sorting
Sort method for sorting
2022-07-28 06:04:00 【ymony】
Sort the array :
// Sort the array
public void arraySort(){ int[] arr = { 1,4,6,333,8,2}; Arrays.sort(arr);// Use java.util.Arrays Object's sort Method for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); }}// Yes list Ascending sort public void listSort1(){ List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(55); list.add(9); list.add(0); list.add(2); Collections.sort(list);// Use Collections Of sort Method for(int a :list){ System.out.println(a); } } // Yes list null public void listSort2(){ List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(55); list.add(9); list.add(0); list.add(2); Collections.sort(list, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return o2 - o1; } });// Use Collections Of sort Method , And rewrite compare Method for(int a :list){ System.out.println(a); } }<br> Be careful :Collections Of sort Methods are arranged in ascending order by default , If you need to arrange in descending order, you need to rewrite conpare Method
from :http://www.cnblogs.com/minshia/p/6283858.html
边栏推荐
猜你喜欢
随机推荐
简单理解一下MVC和三层架构
疫情当下,线下文旅受困,看数字藏品能否解围?
Phoenix
mysql多表查询
Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
记录下在线扩容服务器遇到的问题 NOCHANGE: partition 1 is size 419428319. it cannot be grown
Mars数*字*藏*品*平*台守卫者计划细节公布
文件上传漏洞总结
数字藏品“大乱斗”,千亿市场变局将至?
第七章 单行函数
Tornado初识
regular expression
分布式集群架构场景优化解决方案:Session共享问题
数藏如何实现WEB3.0社交
微服务架构认知、服务治理-Eureka
【三】redis特点功能
Phoenix
ModuleNotFoundError: No module named ‘pip‘
Books - smart investors
NSCTF-web题目writeup









