0

How to bubble sort a arraylist in java?
i want to bubble sort an arraylist. or is there a better way to sort an arraylist or list.

2
  • Bubblesort is a slow algorithm... but it's ok for learning purposes :) Commented Jan 7, 2011 at 8:30
  • Why not go straight to bogosort? Propably useful for learning, too ;) Commented Jan 7, 2011 at 8:31

2 Answers 2

2

is there a better way to sort an arraylist or list.

Yes: use the sorting that is built into the standard library.

For example, http://download.oracle.com/javase/1.4.2/docs/api/java/util/Collections.html#sort%28java.util.List%29

Sign up to request clarification or add additional context in comments.

Comments

0

To sort an ArrayList I used the Collections.sort(), included the in the ArrayList class. eg.

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

To sort it I would say,

Collections.sort(list);

and this would sort the ArrayList

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.