Using Collections to sorting the specified list into ascending order, according to the natural ordering of its elements

package collection.demos;



import java.util.ArrayList;

import java.util.Collections;



public class SortingListDemo {

    public static void main(String[] args) {

        ArrayList<String> names=new ArrayList<String>();

        names.add("Joy");

        names.add("Bynod");

        names.add("Jaxon");

        names.add("Traimer");

        System.out.println("Before Sorting : "+names);

        Collections.sort(names);

        System.out.println("After Sorting : "+names);

    }

}

/*

OUTPUT

Before Sorting : [Joy, Bynod, Jaxon, Traimer]

After Sorting : [Bynod, Jaxon, Joy, Traimer]

 */

No comments:

Popular Posts