English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To sort a Short array, use the Arrays.sort() method.
Let's first declare and initialize an unsorted Short array.
short[] arr = new short[] { 35, 25, 18, 45, 77, 21, 3 };
Now, let's shorten the array.
Arrays.sort(arr);
Below is a complete example of how to sort a Short array in Java.
import java.util.*; public class Demo { public static void main(String[] args) { short[] arr = new short[] { 35, 25, 18, 45, 77, 21, 3 }; System.out.println("Unsorted:"); for (short s : arr) { System.out.println(s); } System.out.println("Sorted:"); Arrays.sort(arr); for (short s : arr) { System.out.println(s); } System.out.println(); } }
Output Result
Unsorted: 35 25 18 45 77 21 3 Sorted: 3 18 21 25 35 45 77