Reference×
Reference
- [] (array access)
- = (assign)
- catch
- class
- // (comment)
- , (comma)
- {} (curly braces)
- /** */ (doc comment)
- . (dot)
- draw()
- exit()
- extends
- final
- false
- import
- implements
- loop()
- /* */ (multiline comment)
- new
- noLoop()
- null
- () (parentheses)
- popStyle()
- pop()
- pushStyle()
- push()
- private
- public
- redraw()
- return
- ; (semicolon)
- setLocation()
- setResizable()
- setTitle()
- setup()
- static
- super
- thread()
- this
- try
- void
- true
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.
Examples
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 sortcount
(int)
number of elements to sort, starting from 0
Return
byte[], char[], int[], float[], or String[]
Related

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.