isSorted

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially using Comparable.compareTo, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

For elements of floating-point types (Double, Float), NaN is considered greater than any other value (including positive infinity), and -0.0 is considered less than 0.0, consistent with Double.compareTo and Float.compareTo.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(arrayOf<String>().isSorted()) // true
println(arrayOf("apple").isSorted()) // true

val sorted = arrayOf("apple", "banana", "cherry")
println(sorted.isSorted()) // true

val unsorted = arrayOf("banana", "apple", "cherry")
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(byteArrayOf().isSorted()) // true
println(byteArrayOf(1).isSorted()) // true

val sorted = byteArrayOf(1, 2, 3, 4, 5)
println(sorted.isSorted()) // true

val unsorted = byteArrayOf(2, 1, 3, 4, 5)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(shortArrayOf().isSorted()) // true
println(shortArrayOf(1).isSorted()) // true

val sorted = shortArrayOf(1, 2, 3, 4, 5)
println(sorted.isSorted()) // true

val unsorted = shortArrayOf(2, 1, 3, 4, 5)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(intArrayOf().isSorted()) // true
println(intArrayOf(1).isSorted()) // true

val sorted = intArrayOf(1, 2, 3, 4, 5)
println(sorted.isSorted()) // true

val unsorted = intArrayOf(2, 1, 3, 4, 5)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(longArrayOf().isSorted()) // true
println(longArrayOf(1L).isSorted()) // true

val sorted = longArrayOf(1L, 2L, 3L, 4L, 5L)
println(sorted.isSorted()) // true

val unsorted = longArrayOf(2L, 1L, 3L, 4L, 5L)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially using Float.compareTo, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

For floating-point arrays, NaN is considered greater than any other value (including positive infinity), and -0.0 is considered less than 0.0, consistent with Float.compareTo.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(floatArrayOf().isSorted()) // true
println(floatArrayOf(1.0f).isSorted()) // true

val sorted = floatArrayOf(1.0f, 2.5f, 3.14f)
println(sorted.isSorted()) // true

val unsorted = floatArrayOf(2.5f, 1.0f, 3.14f)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially using Double.compareTo, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

For floating-point arrays, NaN is considered greater than any other value (including positive infinity), and -0.0 is considered less than 0.0, consistent with Double.compareTo.

Since Kotlin

2.4

Samples

import kotlin.math.abs

fun main() { 
   //sampleStart 
   println(doubleArrayOf().isSorted()) // true
println(doubleArrayOf(1.0).isSorted()) // true

val sorted = doubleArrayOf(1.0, 2.5, 3.14)
println(sorted.isSorted()) // true

val unsorted = doubleArrayOf(2.5, 1.0, 3.14)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(booleanArrayOf().isSorted()) // true
println(booleanArrayOf(false).isSorted()) // true

val sorted = booleanArrayOf(false, false, true)
println(sorted.isSorted()) // true

val unsorted = booleanArrayOf(false, true, false)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(charArrayOf().isSorted()) // true
println(charArrayOf('a').isSorted()) // true

val sorted = charArrayOf('a', 'b', 'c')
println(sorted.isSorted()) // true

val unsorted = charArrayOf('b', 'a', 'c')
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the collection is less than or equal to the following element according to their natural sort order.

Returns true if the collection has fewer than two elements.

The elements are compared sequentially using Comparable.compareTo, and the collection is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Note that the result depends on the iteration order of the collection. The iteration order of some Iterable implementations may be unstable (change from one invocation to the next), in which case this function may return inconsistent results.

For elements of floating-point types (Double, Float), NaN is considered greater than any other value (including positive infinity), and -0.0 is considered less than 0.0, consistent with Double.compareTo and Float.compareTo.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(listOf<String>().isSorted()) // true
println(listOf("apple").isSorted()) // true

val sorted = listOf("apple", "banana", "cherry")
println(sorted.isSorted()) // true

val unsorted = listOf("banana", "apple", "cherry")
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(uintArrayOf().isSorted()) // true
println(uintArrayOf(1u).isSorted()) // true

val sorted = uintArrayOf(1u, 2u, 3u, 4u, 5u)
println(sorted.isSorted()) // true

val unsorted = uintArrayOf(2u, 1u, 3u, 4u, 5u)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ulongArrayOf().isSorted()) // true
println(ulongArrayOf(1uL).isSorted()) // true

val sorted = ulongArrayOf(1uL, 2uL, 3uL, 4uL, 5uL)
println(sorted.isSorted()) // true

val unsorted = ulongArrayOf(2uL, 1uL, 3uL, 4uL, 5uL)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ubyteArrayOf().isSorted()) // true
println(ubyteArrayOf(1u).isSorted()) // true

val sorted = ubyteArrayOf(1u, 2u, 3u, 4u, 5u)
println(sorted.isSorted()) // true

val unsorted = ubyteArrayOf(2u, 1u, 3u, 4u, 5u)
println(unsorted.isSorted()) // false 
   //sampleEnd
}

Returns true if each element in the array is less than or equal to the following element according to their natural sort order.

Returns true if the array has fewer than two elements.

The elements are compared sequentially, and the array is considered sorted if for each pair of adjacent elements the preceding element is not greater than the following one.

Since Kotlin

2.4

Samples


fun main() { 
   //sampleStart 
   println(ushortArrayOf().isSorted()) // true
println(ushortArrayOf(1u).isSorted()) // true

val sorted = ushortArrayOf(1u, 2u, 3u, 4u, 5u)
println(sorted.isSorted()) // true

val unsorted = ushortArrayOf(2u, 1u, 3u, 4u, 5u)
println(unsorted.isSorted()) // false 
   //sampleEnd
}