الفرق بين المراجعتين ل"Kotlin/collections/toMutableList"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط
 
(4 مراجعات متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: الدالة <code>toMutableList()‎</code> في لغة Kotlin}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الدالة <code>toMutableList()‎</code> في Kotlin}}</noinclude>
تعيد الدالة<code>toMutableList()‎</code> [[Kotlin/MutableList|لائحة متغيرة]] تضم جميع عناصر [[Kotlin/Array|المصفوف]] أو [[Kotlin/collections|المجموعة]] التي استُدعيت عبرها.  
+
تحول الدالة <code>toMutableList()‎</code> [[Kotlin/Array|المصفوف]] أو [[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى [[Kotlin/collections/MutableList|قائمة متغيرة]].  
 
==البنية العامة==
 
==البنية العامة==
يمكن استدعاء الدالة<code>toMutableList()‎</code> عبر [[Kotlin/Array|المصفوفات]]:<syntaxhighlight lang="kotlin">
+
يمكن استدعاء الدالة <code>toMutableList()‎</code> مع [[Kotlin/Array|المصفوفات]]:<syntaxhighlight lang="kotlin">
 
fun <T> Array<out T>.toMutableList(): MutableList<T>  
 
fun <T> Array<out T>.toMutableList(): MutableList<T>  
 
fun ByteArray.toMutableList(): MutableList<Byte>  
 
fun ByteArray.toMutableList(): MutableList<Byte>  
سطر 13: سطر 13:
 
fun CharArray.toMutableList(): MutableList<Char>  
 
fun CharArray.toMutableList(): MutableList<Char>  
  
</syntaxhighlight>يمكن استدعاء الدالة<code>toMutableList()‎</code>  عبر المجموعات:<syntaxhighlight lang="kotlin">
+
</syntaxhighlight>ومع المجموعات أيضًا:<syntaxhighlight lang="kotlin">
 
fun <T> Iterable<T>.toMutableList(): MutableList<T>  
 
fun <T> Iterable<T>.toMutableList(): MutableList<T>  
 
fun <T> Collection<T>.toMutableList(): MutableList<T>  
 
fun <T> Collection<T>.toMutableList(): MutableList<T>  
 
</syntaxhighlight>
 
</syntaxhighlight>
==القيمة المُعادة==
+
==القيمة المعادة==
[[Kotlin/MutableList|لائحة متغيرة]] تضم جميع عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/collections|المجموعة]]  التي استُدعيت عبرها.  
+
تُعاد [[Kotlin/collections/MutableList|قائمة متغيرة]] تحوي جميع عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/collections|المجموعة]] المعطاة.  
 
==أمثلة==
 
==أمثلة==
===استخدام الدالة <code>()toMutableList</code> مع المصفوفات===
+
<nowiki/>استعمال الدالة <code>()toMutableList</code> لتحويل مصفوفة إلى قائمة متغيرة:<syntaxhighlight lang="kotlin">
تعرّف الشيفرة الآتية  <nowiki/>[[Kotlin/Array|مصفوفة]] باسم <code>array</code>  مكونة من ثلاثة أعداد باستخدام الدالة <code>()arrayOf‎</code>، ثم تستخدم الدالة <code>()toMutableList</code>  على <code>array</code>، ثم تطبع الناتج:<syntaxhighlight lang="kotlin">
 
 
fun main(args: Array<String>) {
 
fun main(args: Array<String>) {
val array = arrayOf(4, 5, 6)
+
    val array = arrayOf(4, 5, 6)
  
println(array.toMutableList()) // [4, 5, 6]
+
    println(array.toMutableList()) // [4, 5, 6]
 +
    println(array.toMutableList().javaClass.kotlin.qualifiedName) // java.util.ArrayList
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
==أنظر أيضًا==
+
==انظر أيضًا==
*<code>[[Kotlin/collections/toBooleanArray|toBooleanArray()]]</code>‎ : تعيد [[Kotlin/Array|مصفوفة]] من القيم المنطقية (من النوع <code>BooleanArray</code>) تضم جميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع<code>Array<out Boolean>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]]  التي استُدعيت عبرها.
+
* الدالة <code>[[Kotlin/collections/toBooleanArray|toBooleanArray()]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<out Boolean>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من القيم المنطقية (من النوع <code>[[Kotlin/BooleanArray/index|BooleanArray]]</code>).
*<code>[[Kotlin/collections/toByteArray|toByteArray()]]</code>‎ : تعيد <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>ByteArray</code>تضم جميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Byte>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]]  التي استُدعيت عبرها.
+
* الدالة <code>[[Kotlin/collections/toByteArray|toByteArray()]]</code>‎ : تحوِّل <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Byte>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>ByteArray</code>.
*<code>[[Kotlin/collections/toDoubleArray|toDoubleArray()]]</code>‎ : تعيد [[Kotlin/Array|مصفوفة]] من النوع <code>DoubleArray</code>تضم جميع عناصر [[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Double>‎</code>) أو [[Kotlin/collections|المجموعة]]  التي استُدعيت عبرها.
+
* الدالة <code>[[Kotlin/collections/toCharArray|toCharArray()‎]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي التي من النوع <code>Array<Char>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]]  التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>[[Kotlin/CharArray/index|CharArray]]</code>.
 +
* الدالة <code>[[Kotlin/collections/toCollection|toCollection()‎]]</code>: تضيف جميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى المجموعة المتغيرة (MutableCollection) المُمرّرة إليها.
 +
* الدالة <code>[[Kotlin/collections/toDoubleArray|toDoubleArray()]]</code>‎ : تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Double>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>[[Kotlin/DoubleArray/index|DoubleArray]]</code>.
 +
* الدالة <code>[[Kotlin/collections/toFloatArray|toFloatArray()‎]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Float>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]]  التي استُدعيت معها <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>[[Kotlin/FloatArray/index|FloatArray]]</code>.
 +
* الدالة <code>[[Kotlin/collections/toHashSet|toHashSet()]]</code>: تعيد كائنًا من النوع <code>HashSet</code> لجميع عناصر <nowiki/>[[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها.
 +
* الدالة <code>[[Kotlin/collections/toIntArray|toIntArray()‎]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Int>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>IntArray</code>.
 +
* الدالة <code>[[Kotlin/collections/toList|toList()‎]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة]] أو المجموعة التكرارية أو الخريطة التي استُدعيت معها إلى قائمة.
 +
* الدالة <code>[[Kotlin/collections/toLongArray|toLongArray()‎]]</code>: تحول <nowiki/>[[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Long>‎</code>) أو <nowiki/>[[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى <nowiki/>[[Kotlin/Array|مصفوفة]] من النوع <code>LongArray</code>.
 +
 
 +
*الدالة <code>[[Kotlin/collections/toMap|toMap()‎]]</code>: تحول الكائن المستدعى معها إلى خريطة أو تضيف محتوى ذلك الكائن إلى خريطة موجودة مسبقًا.
 +
*الدالة <code>[[Kotlin/collections/toMutableSet|toMutableSet()‎]]</code>: تحول [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها إلى مجموعة من النوع <code>MutableSet</code>.
 +
*الدالة <code>[[Kotlin/collections/toSet|toSet()‎]]</code>: تحول [[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها إلى مجموعة من النوع <code>[[Kotlin/Set|Set]]</code>.
 +
*الدالة <code>[[Kotlin/collections/toShortArray|toShortArray()‎]]</code>: تحول [[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Short>‎</code>) أو [[Kotlin/collections|المجموعة]] التي استُدعيت معها إلى [[Kotlin/Array|مصفوفة]] من النوع <code>ShortArray</code>.
 +
*الدالة <code>[[Kotlin/collections/toSortedSet|toSortedSet()‎]]</code>: تحول [[Kotlin/Array|المصفوفة]] أو [[Kotlin/Iterable|المجموعة التكرارية]] التي استُدعيت معها إلى مجموعة من النوع [[Kotlin/SortedSet|<code>SortedSet</code>]] ثمَّ تعيدها فقط إن لم يمرَّر إليها أي شيء، أو ترتِّبها وفقًا لترتيب معيَّن ثمَّ تعيدها إن مرِّرت إليها دالة مقارنة.
 +
 
 
==مصادر==
 
==مصادر==
* [https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to-mutable-list.html الدالة  toMutableList()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
+
* [https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to-mutable-list.html صفحة الدالة toMutableList()‎ في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.]
 
[[تصنيف:Kotlin]]
 
[[تصنيف:Kotlin]]
[[تصنيف:Kotlin Functions]]
+
[[تصنيف:Kotlin Function]]
 +
[[تصنيف:Kotlin Collection]]

المراجعة الحالية بتاريخ 11:47، 8 سبتمبر 2018

تحول الدالة toMutableList()‎ المصفوف أو المجموعة التي استُدعيت معها إلى قائمة متغيرة.

البنية العامة

يمكن استدعاء الدالة toMutableList()‎ مع المصفوفات:

fun <T> Array<out T>.toMutableList(): MutableList<T> 
fun ByteArray.toMutableList(): MutableList<Byte> 
fun ShortArray.toMutableList(): MutableList<Short> 
fun IntArray.toMutableList(): MutableList<Int> 
fun LongArray.toMutableList(): MutableList<Long> 
fun FloatArray.toMutableList(): MutableList<Float> 
fun DoubleArray.toMutableList(): MutableList<Double>
fun BooleanArray.toMutableList(): MutableList<Boolean> 
fun CharArray.toMutableList(): MutableList<Char>

ومع المجموعات أيضًا:

fun <T> Iterable<T>.toMutableList(): MutableList<T> 
fun <T> Collection<T>.toMutableList(): MutableList<T>

القيمة المعادة

تُعاد قائمة متغيرة تحوي جميع عناصر المصفوفة أو المجموعة المعطاة.

أمثلة

استعمال الدالة ()toMutableList لتحويل مصفوفة إلى قائمة متغيرة:

fun main(args: Array<String>) {
    val array = arrayOf(4, 5, 6)

    println(array.toMutableList()) // [4, 5, 6]
    println(array.toMutableList().javaClass.kotlin.qualifiedName) // java.util.ArrayList
}

انظر أيضًا

مصادر