Java examples for Data Structure:Sort
Returns an alphabetically sorted copy of vector.
//package com.java2s; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { public static void main(String[] argv) { List list = java.util.Arrays.asList("asdf", "java2s.com"); sortListAlphabetically(list);//from ww w. j av a 2 s . c o m } /** Returns an alphabetically sorted copy of vector. */ public static void sortListAlphabetically(List list) { Collections.sort(list, new Comparator() { public int compare(Object a, Object b) { String textA = a.toString(); String textB = b.toString(); return textA.compareToIgnoreCase(textB); } }); } }