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