الفرق بين المراجعتين ل"Kotlin/collections/asList"
< Kotlin | collections
اذهب إلى التنقل
اذهب إلى البحث
جميل-بيلوني (نقاش | مساهمات) ط |
|||
(3 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة) | |||
سطر 1: | سطر 1: | ||
− | <noinclude>{{DISPLAYTITLE: الدالة <code>asList()</code> في | + | <noinclude>{{DISPLAYTITLE: الدالة <code>asList()</code> في Kotlin}}</noinclude> |
− | + | تُعيد الدالة <code>asList()</code> قائمةً (list) تُغلّف المصفوفة الأصلية التي استُدعيت عبرها. | |
==البنية العامة== | ==البنية العامة== | ||
− | + | تختلف بحسب نوع المصفوفة:<syntaxhighlight lang="kotlin"> | |
− | fun <T> Array<out T>. | + | fun <T> Array<out T>.asList(): List<T> |
− | fun ByteArray. | + | fun ByteArray.asList(): List<Byte> |
− | fun ShortArray. | + | fun ShortArray.asList(): List<Short> |
− | fun IntArray. | + | fun IntArray.asList(): List<Int> |
− | fun LongArray. | + | fun LongArray.asList(): List<Long> |
− | fun FloatArray. | + | fun FloatArray.asList(): List<Float> |
− | fun DoubleArray. | + | fun DoubleArray.asList(): List<Double> |
− | fun BooleanArray. | + | fun BooleanArray.asList(): List<Boolean> |
− | fun CharArray. | + | fun CharArray.asList(): List<Char> |
− | </syntaxhighlight> | + | </syntaxhighlight> |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==القيم المعادة== | ==القيم المعادة== | ||
− | + | قائمة (list) تُغلّف المصفوفة الأصلية التي استُدعيت عبرها. | |
==أمثلة== | ==أمثلة== | ||
− | + | تعرِّف الشيفرة الآتية مصفوفةً باسم <code>array</code> مكوَّنة من حرفين باستخدام الدالة <code>()arrayOf</code>، ثم تنشئ قائمةً باسم <code>list</code> من المصفوفة <code>array</code> وذلك باستخدام الدالة <code>()asList</code> ثم تطبع تلك القائمة:<syntaxhighlight lang="kotlin"> | |
− | |||
fun main(args: Array<String>) { | fun main(args: Array<String>) { | ||
− | val array = arrayOf( | + | val array = arrayOf("a", "b") |
− | val | + | val list = array.asList() |
− | + | ||
− | + | println(list) // [a, b] | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==انظر أيضًا== | ==انظر أيضًا== | ||
− | *<code>[[Kotlin/collections/ | + | *الدالة <code>[[Kotlin/collections/asIterable|asIterable()]]</code>: تُعيد نسخةً تكراريّةً (iterable instance) تُغلّف (wrap) المصفوفة الأصلية وتعيد عناصرَها عندما تُستخدَم في حلقات التكرار (مثل <code>[[Kotlin/control flow#.D8.AA.D8.B9.D8.A8.D9.8A.D8.B1 for|for]]</code>). |
− | *<code>[[Kotlin/collections/asSequence|asSequence()]]</code>: تعيد | + | *الدالة <code>[[Kotlin/collections/asSequence|asSequence()]]</code>: تعيد نسخةً من النوع <code>sequence</code> والتي تُغلّف المصفوفة الأصليّة وتعيد عناصرها عندما تُستخدَم في حلقات التكرار (مثل حلقة <code>[[Kotlin/control flow#.D8.AA.D8.B9.D8.A8.D9.8A.D8.B1 for|for]]</code>). |
− | ==مصادر | + | ==مصادر<span> </span>== |
− | <span> </span> | + | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-list.html صفحة الدالة ()asList في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.] |
− | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as- | ||
[[تصنيف:Kotlin]] | [[تصنيف:Kotlin]] | ||
− | [[تصنيف:Kotlin | + | [[تصنيف:Kotlin Function]] |
+ | [[تصنيف:Kotlin Collection]] |
المراجعة الحالية بتاريخ 07:04، 8 سبتمبر 2018
تُعيد الدالة asList()
قائمةً (list) تُغلّف المصفوفة الأصلية التي استُدعيت عبرها.
البنية العامة
تختلف بحسب نوع المصفوفة:
fun <T> Array<out T>.asList(): List<T>
fun ByteArray.asList(): List<Byte>
fun ShortArray.asList(): List<Short>
fun IntArray.asList(): List<Int>
fun LongArray.asList(): List<Long>
fun FloatArray.asList(): List<Float>
fun DoubleArray.asList(): List<Double>
fun BooleanArray.asList(): List<Boolean>
fun CharArray.asList(): List<Char>
القيم المعادة
قائمة (list) تُغلّف المصفوفة الأصلية التي استُدعيت عبرها.
أمثلة
تعرِّف الشيفرة الآتية مصفوفةً باسم array
مكوَّنة من حرفين باستخدام الدالة ()arrayOf
، ثم تنشئ قائمةً باسم list
من المصفوفة array
وذلك باستخدام الدالة ()asList
ثم تطبع تلك القائمة:
fun main(args: Array<String>) {
val array = arrayOf("a", "b")
val list = array.asList()
println(list) // [a, b]
}
انظر أيضًا
- الدالة
asIterable()
: تُعيد نسخةً تكراريّةً (iterable instance) تُغلّف (wrap) المصفوفة الأصلية وتعيد عناصرَها عندما تُستخدَم في حلقات التكرار (مثلfor
). - الدالة
asSequence()
: تعيد نسخةً من النوعsequence
والتي تُغلّف المصفوفة الأصليّة وتعيد عناصرها عندما تُستخدَم في حلقات التكرار (مثل حلقةfor
).