Returns an alphabetically sorted copy of vector. - Java Data Structure

Java examples for Data Structure:Sort

Description

Returns an alphabetically sorted copy of vector.

Demo Code


//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);
            }
        });
    }
}

Related Tutorials