الفرق بين المراجعتين ل"Kotlin/collections/asList"
< Kotlin | collections
اذهب إلى التنقل
اذهب إلى البحث
(أنشأ الصفحة ب' Kotlin/collections/asIterable نقاش ابحث عن ... أحدث التغييرات صفحة عشوائية أدوات ماذا يصل هنا تغييرات ذ...') |
جميل-بيلوني (نقاش | مساهمات) ط |
||
(4 مراجعات متوسطة بواسطة 3 مستخدمين غير معروضة) | |||
سطر 1: | سطر 1: | ||
+ | <noinclude>{{DISPLAYTITLE: الدالة <code>asList()</code> في Kotlin}}</noinclude> | ||
+ | تُعيد الدالة <code>asList()</code> قائمةً (list) تُغلّف المصفوفة الأصلية التي استُدعيت عبرها. | ||
+ | ==البنية العامة== | ||
+ | تختلف بحسب نوع المصفوفة:<syntaxhighlight lang="kotlin"> | ||
+ | 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> | ||
+ | </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>) { | ||
+ | val array = arrayOf("a", "b") | ||
+ | val list = array.asList() | ||
− | + | println(list) // [a, b] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | انظر أيضًا | + | </syntaxhighlight> |
− | + | ==انظر أيضًا== | |
− | asSequence(): تعيد | + | *الدالة <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>sequence</code> والتي تُغلّف المصفوفة الأصليّة وتعيد عناصرها عندما تُستخدَم في حلقات التكرار (مثل حلقة <code>[[Kotlin/control flow#.D8.AA.D8.B9.D8.A8.D9.8A.D8.B1 for|for]]</code>). |
− | + | ==مصادر<span> </span>== | |
− | + | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/as-list.html صفحة الدالة ()asList في التوثيق الرسميّ للمكتبة القياسيّة في لغة 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
).