s-day03--Collections里面的sort方法
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.colletions04;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/*
|
||||||
|
static <T> void sort(List<T> list) 根据其元素的自然排序,按照升序排列指定的列表。
|
||||||
|
*/
|
||||||
|
public class Demo12 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//整数的自然排序:123456
|
||||||
|
List<Integer> lists = new ArrayList<>();
|
||||||
|
Collections.addAll(lists, 100, 55, 33, 66, 7, 89, 44);
|
||||||
|
System.out.println(lists);
|
||||||
|
Collections.sort(lists);//升序排序
|
||||||
|
System.out.println(lists);
|
||||||
|
//字符串的自然排序
|
||||||
|
List<String> strList = new ArrayList<>();
|
||||||
|
Collections.addAll(strList, "cb", "bb", "ab", "ba", "ca");
|
||||||
|
System.out.println(strList);
|
||||||
|
Collections.sort(strList);
|
||||||
|
System.out.println(strList);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user