0

If you had an array of Strings, what is the quickest way to sort this array in ascending order ?

Coral Doe
  • 1,925
  • 3
  • 19
  • 36
Johanna
  • 27,036
  • 42
  • 89
  • 117

4 Answers4

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.

Community
  • 1
  • 1
akarnokd
  • 69,132
  • 14
  • 157
  • 192
2
String[] Mystring = {"cat","lion", "dog", "mouse"};
Arrays.sort(Mystring);

Sorting Arrays

TStamper
  • 30,098
  • 10
  • 66
  • 73
1

Arrays.sort(Object)

Arrays.sort(T[] a, Comparator<? super T> c)

bruno conde
  • 47,767
  • 15
  • 98
  • 117