# Simplify Sorted-Order Validation with Kotlin 2.4.0's New Extensions

DevFeed: [Simplify Sorted-Order Validation with Kotlin 2.4.0's New Extensions](<https://devfeed.tech/articles/simplify-sorted-order-validation-with-kotlin-2-4-0-s-new-extensions-25978.md>)

Original publisher: [Read original article](<https://navczydev.medium.com/simplify-sorted-order-validation-with-kotlin-2-4-0s-new-extensions-b48b1ac10521?source=rss-711ab22c5c77------2>)

Author: Nav Singh

Published: 2026-04-06T02:23:40Z

Content type: tutorial

Language: en

Sources: [Stories by Nav Singh 🇨🇦 on Medium](<https://devfeed.tech/sources/stories-by-nav-singh-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [extension](<https://devfeed.tech/tags/extension.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-2](<https://devfeed.tech/tags/kotlin-2.md>), [kotlin-beginners](<https://devfeed.tech/tags/kotlin-beginners.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [library](<https://devfeed.tech/tags/library.md>), [sortedlist](<https://devfeed.tech/tags/sortedlist.md>), [sorting](<https://devfeed.tech/tags/sorting.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

## AI overview

This article introduces Kotlin 2.4.0-Beta1 standard-library extension functions for checking whether collections are sorted. It covers ascending, descending, comparator-based, and selector-based checks, which return true for correctly ordered collections or collections with fewer than two elements. The checks stop when they find an unordered pair.

## Source excerpt

Image generated using Perplexity Kotlin 2.4.0-Beta1 introduces a small but powerful addition to the standard library: a set of new extension functions that lets us check whether a collection is already sorted. With these extension functions, we can check whether elements have already been sorted without resorting them. New Functions .isSorted() .isSortedDescending() .isSortedWith(comparator) .isSortedBy(selector) .isSortedByDescending(selector) All of these return true if: The elements are in the expected order, or The collection has fewer than two elements.These functions are optimized -- they stop checking as soon as an unordered pair is found, so they handle large inputs efficiently.Code samplesdata class User(val name: String, val age: Int)fun main() { val numbers = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) println("Numbers: isSorted") println(numbers.isSorted()) // true println("Is sorted descending") println(numbers.isSortedDescending()) // false // Users list val users = listOf( User("Alice", 21), User("Balley", 34), User("Charles", 29), ) println("Users: isSorted by Age") println(users.isSortedBy(User::age)) // false val comparator = Comparator<User>{ user, user2 -> user.name.length.compareTo(user2.name.length) } println("Users: isSortedWith(comparator)") val sortedList = users.sortedWith(comparator) println("Users: Name by length ${sortedList.joinToString()}") // Output: Users: Name by length User(name=Bob, age=31), User(name=Alice, age=24), User(name=Charlie, age=29) println(sortedList.isSortedWith(comparator)) // true }References What's new in Kotlin 2.4.0-Beta1 | Kotlin