الفرق بين المراجعتين ل"Kotlin/collections/sorted"
< Kotlin | collections
اذهب إلى التنقل
اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة <code>sorted()</code> في لغة Kotlin}}</noinclude> تقوم الدالة<code>sorted()</code> بترتيب Kotlin/Ar...') |
جميل-بيلوني (نقاش | مساهمات) ط |
||
(5 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة) | |||
سطر 1: | سطر 1: | ||
− | <noinclude>{{DISPLAYTITLE: الدالة <code>sorted()</code> في | + | <noinclude>{{DISPLAYTITLE: الدالة <code>sorted()</code> في Kotlin}}</noinclude> |
− | + | ترتِّب الدالة <code>sorted()</code> جميع عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في [[Kotlin/List|قائمة]]. | |
==البنية العامة== | ==البنية العامة== | ||
− | + | <nowiki/><nowiki/><syntaxhighlight lang="kotlin"> | |
− | fun | + | fun <T : Comparable<T>> Array<out T>.sorted(): List<T> |
− | fun | + | fun ByteArray.sorted(): List<Byte> |
− | fun | + | fun ShortArray.sorted(): List<Short> |
− | fun | + | fun IntArray.sorted(): List<Int> |
− | fun | + | fun LongArray.sorted(): List<Long> |
− | fun FloatArray. | + | fun FloatArray.sorted(): List<Float> |
− | fun CharArray. | + | fun DoubleArray.sorted(): List<Double> |
− | + | fun CharArray.sorted(): List<Char> | |
+ | fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> | ||
+ | </syntaxhighlight> | ||
− | + | == القيمة المعادة == | |
− | + | تُعاد [[Kotlin/List|قائمة]] تضم عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] المعطاة بعد ترتيبها تصاعديًّا. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==أمثلة== | ==أمثلة== | ||
− | + | <nowiki/><nowiki/>استعمال الدالة <code>()sorted</code> لترتيب عناصر مصفوفة تصاعديًّا:<syntaxhighlight lang="kotlin"> | |
− | |||
− | |||
− | |||
fun main(args: Array<String>) { | fun main(args: Array<String>) { | ||
− | val array = arrayOf(1, 9, 3, 7, 5, 6 | + | val array = arrayOf(1, 9, -3, 7, 5, 6) |
− | |||
− | |||
− | print ( | + | print(array.sorted()) // [-3, 1, 5, 6, 7, 9] |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==انظر أيضًا== |
− | *<code>[[Kotlin/collections/ | + | *الدالة <code>[[Kotlin/collections/sortedArray|sortedArray()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في [[Kotlin/List|مصفوفة]] جديدة. |
+ | *الدالة <code>[[Kotlin/collections/sortedArrayDescending|sortedArrayDescending()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في [[Kotlin/List|مصفوفة]] جديدة. | ||
+ | *الدالة <code>[[Kotlin/collections/sortedArrayWith|sortedArrayWith()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في مصفوفة جديدة. | ||
+ | *الدالة <code>[[Kotlin/collections/sortedBy|sortedBy()]]</code>: عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر. | ||
+ | *الدالة <code>[[Kotlin/collections/sortedByDescending|sortedByDescending()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] (Iterable) التي استُدعيت معها تنازليًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر ثمَّ تضع الناتج في قائمة. | ||
+ | *الدالة <code>[[Kotlin/collections/sortedDescending|sortedDescending()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في [[Kotlin/List|قائمة]]. | ||
+ | *الدالة <code>[[Kotlin/collections/sortedWith|sortedWith()]]</code>: ترتِّب جميع عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في قائمة. | ||
+ | |||
+ | * الدالة <code>[[Kotlin/collections/sort|sort()]]</code> : ترتب <nowiki/>[[Kotlin/Array|المصفوفة]] أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا. | ||
+ | |||
==مصادر== | ==مصادر== | ||
− | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/ | + | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sorted.html صفحة الدالة sorted() في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.] |
[[تصنيف:Kotlin]] | [[تصنيف:Kotlin]] | ||
− | [[تصنيف:Kotlin | + | [[تصنيف:Kotlin Function]] |
+ | [[تصنيف:Kotlin Collection]] |
المراجعة الحالية بتاريخ 11:12، 8 سبتمبر 2018
ترتِّب الدالة sorted()
جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في قائمة.
البنية العامة
fun <T : Comparable<T>> Array<out T>.sorted(): List<T>
fun ByteArray.sorted(): List<Byte>
fun ShortArray.sorted(): List<Short>
fun IntArray.sorted(): List<Int>
fun LongArray.sorted(): List<Long>
fun FloatArray.sorted(): List<Float>
fun DoubleArray.sorted(): List<Double>
fun CharArray.sorted(): List<Char>
fun <T : Comparable<T>> Iterable<T>.sorted(): List<T>
القيمة المعادة
تُعاد قائمة تضم عناصر المصفوفة أو المجموعة التكرارية المعطاة بعد ترتيبها تصاعديًّا.
أمثلة
استعمال الدالة ()sorted
لترتيب عناصر مصفوفة تصاعديًّا:
fun main(args: Array<String>) {
val array = arrayOf(1, 9, -3, 7, 5, 6)
print(array.sorted()) // [-3, 1, 5, 6, 7, 9]
}
انظر أيضًا
- الدالة
sortedArray()
: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها تصاعديًّا ثمَّ تضع الناتج في مصفوفة جديدة. - الدالة
sortedArrayDescending()
: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في مصفوفة جديدة. - الدالة
sortedArrayWith()
: ترتِّب جميع عناصر المصفوفة التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في مصفوفة جديدة. - الدالة
sortedBy()
: عناصر المصفوفة أو القائمة المتغيرة (MutableList) التي استُدعيت معها تصاعديًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر. - الدالة
sortedByDescending()
: ترتِّب جميع عناصر المصفوفة أو المجموعة التكرارية (Iterable) التي استُدعيت معها تنازليًّا وفقًا للقيم التي تعيدها الدالة المُمرّرة إليها عند تطبيقها على كل عنصر ثمَّ تضع الناتج في قائمة. - الدالة
sortedDescending()
: ترتِّب جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها تنازليًّا ثمَّ تضع الناتج في قائمة. - الدالة
sortedWith()
: ترتِّب جميع عناصر المصفوفة أو المجموعة التكرارية التي استُدعيت معها وفقًا للمُقارِن المُمرّر إليها ثمَّ تضع الناتج في قائمة.