Example sort Array
ตัวอย่างการ sort ข้อมูลใน Array อย่างง่าย
/** * File Name : SortArray.java * Created Date : Dec 15, 2009 : 2:36:39 PM * Copyright © 2009 www.fun4station.com */ package com.fun4station.example; import java.util.Arrays; import java.util.Collections; /** * @Author Supot Saelao * @Version 1.0 */ public class SortArray { public static void main(String[] args) { Integer[] datas = new Integer[] { 9, 2, 5, 1, 6, 4, 3, 8, 7, 0 }; //Sort by ascending Arrays.sort(datas); for (Integer data : datas) { System.out.print(data + " "); } System.out.println(); //Sort by descending Arrays.sort(datas, Collections.reverseOrder()); for (int data : datas) { System.out.print(data + " "); } } }
No comments yet.