If you had an array of Strings, what is the quickest way to sort this array in ascending order ?
Asked
Active
Viewed 397 times
4 Answers
8
See java.util.Arrays.sort(Object[])
import java.util.*;
Arrays.sort(stringarray)

lavinio
- 23,931
- 5
- 55
- 71
2
Arrays.sort() for now.
Also I heard that Josh Bloch is working on a much faster sort algorithm than the current mergesort. (I can't remember where, maybe in this interview. The new algorithm will perform better for partially sorted arrays and originates from a Python? sort implementation). Also see this question.
2
String[] Mystring = {"cat","lion", "dog", "mouse"};
Arrays.sort(Mystring);

TStamper
- 30,098
- 10
- 66
- 73