Java Sort short Array : short « Data Type « Java






Java Sort short Array

   

import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    short[] s1 = new short[] { 31, 21, 51, 41, 11 };
    for (short s : s1) {
      System.out.print(" " + s);
    }
    Arrays.sort(s1);
    for (short s : s1) {
      System.out.print(" " + s);
    }

    short[] s2 = new short[] { 5, 2, 3, 1, 4 };
    Arrays.sort(s2, 1, 4);

    for (short s : s2) {
      System.out.print(" " + s);
    }
  }
}

   
    
    
  








Related examples in the same category

1.Java Short Example
2.Java short: short is 16 bit signed type ranges from –32,768 to 32,767.
3.Convert Java String to Short
4.Short class creates primitives that wrap themselves around data items of the short data type
5.Use toString method of Short class to convert Short into String.
6.Use Short constructor to convert short primitive type to Short object
7.short value
8.Convert Short to numeric primitive data types
9.Convert String to short primitive
10.Compare Two Java short Arrays
11.Cast back to short
12.Cast result of plus operation to byte
13.Shorts Vs IntsShorts Vs Ints
14.Gets the maximum of three short values.
15.Gets the minimum of three short values.
16.Convert int and short to bytes