Home Answers Viewqa Java-Beginners Sorting arraylist without using Collection.sort()

 
 


Sing S
Sorting arraylist without using Collection.sort()
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners

Hi,

How can I sort an arraylist without using Collection.sort() nad also I am not allowed to use any other data structure in the program? Is there any algorithm by using which I can do this?

Please help ....

View Answers

February 8, 2011 at 5:10 PM


Java Sort list without using Collections.sort() method

import java.util.*;
class SortList 
{
    public static void main(String[] args) 
    {
        ArrayList<String> list=new ArrayList<String>();
        list.add("D");
        list.add("B");
        list.add("A");
        list.add("E");
        list.add("C");

    Object arr[] = list.toArray(); 
    Arrays.sort(arr);
    for(int i=0;i<arr.length;i++){
    System.out.println(arr[i].toString());
     }
    }
}









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.