Java Arrays sort an array

Description

Java Arrays sort an array


import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    int[] intArray = { 431, 1235, 931, 1230, 5433, 5345, 65345, 2543 };

    Arrays.sort(intArray);// w ww. j a v  a 2 s  .co  m

    System.out.println(Arrays.toString(intArray));

    String[] stringArray = { "Java", "CSS", "HTML", "Javascript", "SQL" };

    Arrays.sort(stringArray);

    System.out.println(Arrays.toString(stringArray));

  }
}
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws Exception {

    // Sort Array of byte
    byte[] myArray = { 65, 62, 67, 13, 19 };
    Arrays.sort(myArray);/*  w  ww  .j av  a 2s.c o m*/
    System.out.println(Arrays.toString(myArray));

    // Sort Array of char
    char[] myArray2 = { 'd', 'e', 'm', '0', 's' };
    Arrays.sort(myArray2);
    System.out.println(Arrays.toString(myArray2));

    // Sort Array of short
    short[] myArray3 = { 515, 122, 700, 301, 129 };
    Arrays.sort(myArray3);
    System.out.println(Arrays.toString(myArray3));
    
    // Sort Array of int
    int[] myArray4 = { 5, 2, 7, 3, 9 };
    Arrays.sort(myArray4);
    System.out.println(Arrays.toString(myArray4));
    
    // Sort Array of long
    long[] myArray5 = { 12, 321, 567, 366, 94};
    Arrays.sort(myArray5);
    System.out.println(Arrays.toString(myArray5));

    // Sort Array of float
    float[] myArray6 = { 12.5f, 20.50f, 30.35f, 39.5f, 90.11f };
    Arrays.sort(myArray6);
    System.out.println(Arrays.toString(myArray6));

    // Sort Array of double
    double[] myArray7 = { 1.45d, 10.65d, 71.25d, 93.15d, 19.75d };
    Arrays.sort(myArray7);
    System.out.println(Arrays.toString(myArray7));

  }
}



PreviousNext

Related