1.

How to sort a Short array in Java

Answer»

The Arrays.sort() method is PROVIDED in Java to sort Short array.

Let us see an example:

import java.util.*; PUBLIC class Example {     public static void main(String []args){     short[] shortArr = new short[] { 35, 25, 18, 45, 77, 21, 3 };     System.out.println("Unsorted:");     for (short a : shortArr) {      System.out.print(a+" ");     }     System.out.println("\nSorted Array = ");     // sort array     Arrays.sort(shortArr);     for (short a : shortArr) {      System.out.print(a+" ");     }     System.out.println();     } }

The output:

Unsorted: 35 25 18 45 77 21 3 Sorted Array = 3 18 21 25 35 45 77


Discussion

No Comment Found