Name

sort()

Description

Sorts an array of numbers from smallest to largest, or puts an array of words in alphabetical order. The original array is not modified; a re-ordered array is returned. The count parameter states the number of elements to sort. For example, if there are 12 elements in an array and count is set to 5, only the first 5 elements in the array will be sorted. Copy

float[] a = { 3.4, 3.6, 2, 0, 7.1 };
a = sort(a);
println(a);
// Prints the contents of the sorted array:
// [0] 0.0
// [1] 2.0
// [2] 3.4
// [3] 3.6
// [4] 7.1
  • String[] s = { "deer", "elephant", "bear", "aardvark", "cat" };
    s = sort(s);
    println(s);
    // Prints the contents of the sorted array:
    // [0] "aardvark"
    // [1] "bear"
    // [2] "cat"
    // [3] "deer"
    // [4] "elephant"
    
  • String[] s = { "deer", "elephant", "bear", "aardvark", "cat" };
    s = sort(s, 3);
    println(s);
    // Prints the contents of the array, with the first 3 elements sorted:
    // [0] "bear"
    // [1] "deer"
    // [2] "elephant"
    // [3] "aardvark"
    // [4] "cat"
    
  • Syntax

    • sort(list)
    • sort(list, count)

    Parameters

    • list(byte[], char[], int[], float[], String[])array to sort
    • count(int)number of elements to sort, starting from 0

    Return

    • byte[], char[], int[], float[], or String[]

    Related