الفرق بين المراجعتين لصفحة: «Kotlin/collections/toCollection»
< Kotlin | collections
أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: الدالة <code>toCollection()</code> في لغة Kotlin}}</noinclude> تعيد الدالة<code>toCollection()</code> Kotlin/Arra...' |
لا ملخص تعديل |
||
| سطر 1: | سطر 1: | ||
تضيف الدالة<code>toCollection()</code> عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/collections|المجموعة]] التي استُدعيت عبرها إلى [[Kotlin/MutableCollection|المجموعة المتغيرة]] (<code>MutableCollection</code>) المُمرّرة <code>destination</code>. | |||
==البنية العامة== | ==البنية العامة== | ||
<syntaxhighlight lang="kotlin"> | <syntaxhighlight lang="kotlin"> | ||
fun Array<out Float>. | fun <T, C : MutableCollection<in T>> Array<out T>.toCollection( | ||
fun | destination: C | ||
): C | |||
fun <C : MutableCollection<in Byte>> ByteArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Short>> ShortArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Int>> IntArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Long>> LongArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Float>> FloatArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Double>> DoubleArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Boolean>> BooleanArray.toCollection( | |||
destination: C | |||
): C | |||
fun <C : MutableCollection<in Char>> CharArray.toCollection( | |||
destination: C | |||
): C | |||
fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection( | |||
destination: C | |||
): C | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==القيمة المُعادة== | ==القيمة المُعادة== | ||
[[Kotlin/ | [[Kotlin/MutableCollection|المجموعة المتغيرة]] (<code>MutableCollection</code>) المُمرّرة <code>destination</code> بعد إضافة عناصر [[Kotlin/Array|المصفوفة]] أو [[Kotlin/collections|المجموعة]] التي استُدعيت عبرها الدالة. | ||
==أمثلة== | ==أمثلة== | ||
===استخدام الدالة <code>()toCollection</code> مع المصفوفات=== | ===استخدام الدالة <code>()toCollection</code> مع المصفوفات=== | ||
تعرّف الشيفرة الآتية <nowiki/>[[Kotlin/Array|مصفوفة]] باسم <code>array</code> | تعرّف الشيفرة الآتية <nowiki/>[[Kotlin/Array|مصفوفة]] باسم <code>array</code> مكونة من ثلاثة أعداد باستخدام الدالة <code>()arrayOf</code>، ثم تعرّف <nowiki/>[[Kotlin/mutableListOf|لائحة متغيرة]] باسم <code>list</code> مكونة من ثلاثة أعداد باستخدام الدالة <code>()mutableListOf</code>، ثم تستخدم الدالة <code>()toCollection</code> على <code>array</code> وتمرر <code>list</code> كوسيط، ثم تطبع الناتج:<syntaxhighlight lang="kotlin"> | ||
fun main(args: Array<String>) { | fun main(args: Array<String>) { | ||
val array | val array = arrayOf(4, 5, 6) | ||
println | var list = mutableListOf(8, 7, 3) | ||
println(array.toCollection(list)) // [8, 7, 3, 4, 5, 6] | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| سطر 24: | سطر 51: | ||
*<code>[[Kotlin/collections/toDoubleArray|toDoubleArray()]]</code> : تعيد [[Kotlin/Array|مصفوفة]] من النوع <code>DoubleArray</code>تضم جميع عناصر [[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Double></code>) أو [[Kotlin/collections|المجموعة]] التي استُدعيت عبرها. | *<code>[[Kotlin/collections/toDoubleArray|toDoubleArray()]]</code> : تعيد [[Kotlin/Array|مصفوفة]] من النوع <code>DoubleArray</code>تضم جميع عناصر [[Kotlin/Array|المصفوفة العامة]] (أي من النوع <code>Array<Double></code>) أو [[Kotlin/collections|المجموعة]] التي استُدعيت عبرها. | ||
==مصادر== | ==مصادر== | ||
* [https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to- | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to-collection.html الدالة toCollection() في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.] | ||
[[تصنيف:Kotlin]] | [[تصنيف:Kotlin]] | ||
[[تصنيف:Kotlin Functions]] | [[تصنيف:Kotlin Functions]] | ||
مراجعة 22:47، 23 يونيو 2018
تضيف الدالةtoCollection() عناصر المصفوفة أو المجموعة التي استُدعيت عبرها إلى المجموعة المتغيرة (MutableCollection) المُمرّرة destination.
البنية العامة
fun <T, C : MutableCollection<in T>> Array<out T>.toCollection(
destination: C
): C
fun <C : MutableCollection<in Byte>> ByteArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Short>> ShortArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Int>> IntArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Long>> LongArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Float>> FloatArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Double>> DoubleArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Boolean>> BooleanArray.toCollection(
destination: C
): C
fun <C : MutableCollection<in Char>> CharArray.toCollection(
destination: C
): C
fun <T, C : MutableCollection<in T>> Iterable<T>.toCollection(
destination: C
): C
القيمة المُعادة
المجموعة المتغيرة (MutableCollection) المُمرّرة destination بعد إضافة عناصر المصفوفة أو المجموعة التي استُدعيت عبرها الدالة.
أمثلة
استخدام الدالة ()toCollection مع المصفوفات
تعرّف الشيفرة الآتية مصفوفة باسم array مكونة من ثلاثة أعداد باستخدام الدالة ()arrayOf، ثم تعرّف لائحة متغيرة باسم list مكونة من ثلاثة أعداد باستخدام الدالة ()mutableListOf، ثم تستخدم الدالة ()toCollection على array وتمرر list كوسيط، ثم تطبع الناتج:
fun main(args: Array<String>) {
val array = arrayOf(4, 5, 6)
var list = mutableListOf(8, 7, 3)
println(array.toCollection(list)) // [8, 7, 3, 4, 5, 6]
}
أنظر أيضًا
toBooleanArray() : تعيد مصفوفة من القيم المنطقية (من النوعBooleanArray) تضم جميع عناصر المصفوفة العامة (أي من النوعArray<out Boolean>) أو المجموعة التي استُدعيت عبرها.toByteArray() : تعيد مصفوفة من النوعByteArrayتضم جميع عناصر المصفوفة العامة (أي من النوعArray<Byte>) أو المجموعة التي استُدعيت عبرها.toDoubleArray() : تعيد مصفوفة من النوعDoubleArrayتضم جميع عناصر المصفوفة العامة (أي من النوعArray<Double>) أو المجموعة التي استُدعيت عبرها.