Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Sing S
Sorting arraylist without using Collection.sort()
1 Answer(s)      3 years and 11 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 ....


Advertisement
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 Tutorials/Questions & Answers:
 

 

 

DMCA.com