import java.util.*; public class TestSort { public static void main(String[] args) { int[] a = {1, 3, 6, 7, 0, 2, 5, 8, 4, 9}; List l = new LinkedList(); for(int i=0; i<a.length; i++){ l.add(a[i]); //將a陣列元素依序放入List中 } Collections.sort(l); //正序排序 System.out.println(l); Collections.reverse(l); //逆序排序 System.out.println(l); System.out.println(Collections.binarySearch(l,5)); //二分搜尋法,找到5的位置 Collections.shuffle(l); //亂序排序 System.out.println(l); } } |
全站熱搜