[java] Sort an array in Java

Be aware that Arrays.sort() method is not thread safe: if your array is a property of a singleton, and used in a multi-threaded enviroment, you should put the sorting code in a synchronized block, or create a copy of the array and order that copy (only the array structure is copied, using the same objects inside).

For example:

 int[] array = new int[10];
 ...
 int[] arrayCopy = Arrays.copyOf(array , array .length);
 Arrays.sort(arrayCopy);
 // use the arrayCopy;