import java.util.ArrayList; import java.util.Collections; public class CollectionTest { public static void main(String[] args) { ArrayList <Integer> list = new ArrayList<> (); list.add(50); Integer[] fruit = {10,60,20,90 }; for(Integer p : fruit) list.add(p); System.out.println("Number : "+ list); Collections.sort(list); System.out.println("Number(順排) : "+ list); Collections.reverse(list); System.out.println("Number(反排) : "+ list); } }執行結果
沒有留言:
張貼留言