05 March, 2014

Custom Comparator in Java

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Jignesh Vachhani
 *
 */


public class Test
{

    /**
     * @param args
     */
   
    private List<String> getSortedString()
    {
        List<String> locales = Arrays.asList("jignesh","vachhani");
        Collections.sort(locales, new Comparator<String>()
        {
            @Override
            public int compare(String aO1, String aO2)
            {
                return aO1.compareTo(aO2);
            }
        });
        return locales;
    }
   
    public static void main(String[] args)
    {
        Test t = new Test();
        System.out.println(t.getSortedString());

    }
}
OutPut : 
[jignesh,vachhani]

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...