ตัวอย่าง
package demo.loop; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SortListExample { /** * @param args */ public static void main(String[] args) { Listผลลัพธ์ที่ได้คือunsortList = new ArrayList (); unsortList.add("Java"); unsortList.add("XML"); unsortList.add("1"); unsortList.add("AJAX"); unsortList.add("SQL"); unsortList.add("2"); unsortList.add("ASP.Net"); unsortList.add("3"); unsortList.add("JavaScript"); //before sort System.out.println("List is unsort ............."); for(String temp: unsortList){ System.out.println(temp); } //sort the list Collections.sort(unsortList); //after sorted System.out.println("List is sorted............."); for(String temp: unsortList){ System.out.println(temp); } } }
List is unsort ............. Java XML 1 AJAX SQL 2 ASP.Net 3 JavaScript List is sorted............. 1 2 3 AJAX ASP.Net Java JavaScript SQL XML
0 comments:
Post a Comment