close
標題:

Java ArrayList 點去 sort

發問:

aa.jpg

 

此文章來自奇摩知識+如有不便請留言告知

I have a ArrayList This contain <50,10,20,87,41> 我要用java build in 左既 quicksort method 去 sort, 個method 叫咩名? 如: ArrayList a1 = new ArrayList(); a1 點 sort? 用Connections.sort(a1) ? 但係佢又有error wor. 請各位高手指教. 要俾code

最佳解答:

import java.util.ArrayList; public class SortTest { public static void print(ArrayList a) { for(int i=0;i< a.size();i++) System.out.printf("%d ",a.get(i)); System.out.println(); } public static void main(String[] args) { ArrayList< Integer> a=new ArrayList< Integer>(); a.add(50); a.add(10); a.add(20); a.add(87); a.add(41); print(a); java.util.Collections.sort(a); print(a); } } Output: 50 10 20 87 41 10 20 41 50 87 Press any key to continue . . .

其他解答:
arrow
arrow

    gbu94mz95e 發表在 痞客邦 留言(0) 人氣()