الفرق بين المراجعتين ل"Kotlin/collections/slice"
< Kotlin | collections
اذهب إلى التنقل
اذهب إلى البحث
جميل-بيلوني (نقاش | مساهمات) ط (مراجعة وتدقيق.) |
|||
سطر 1: | سطر 1: | ||
− | <noinclude>{{DISPLAYTITLE: الدالة <code>slice()</code> في | + | <noinclude>{{DISPLAYTITLE: الدالة <code>slice()</code> في Kotlin}}</noinclude> |
− | + | تقطع الدالة <code>slice()</code> جزءًا محدَّدًا من [[Kotlin/Array|المصفوفة]] أو [[Kotlin/List|القائمة]] التي استُدعيت معها ثمَّ تعيده في قائمة. | |
==البنية العامة== | ==البنية العامة== | ||
− | يمكن تمرير [[Kotlin/ranges|مجال]] | + | يمكن تمرير [[Kotlin/ranges|مجال]] محدَّد إلى الدالة <code>slice()</code> كوسيط:<nowiki/><nowiki/><syntaxhighlight lang="kotlin"> |
fun <T> Array<out T>.slice(indices: IntRange): List<T> | fun <T> Array<out T>.slice(indices: IntRange): List<T> | ||
fun ByteArray.slice(indices: IntRange): List<Byte> | fun ByteArray.slice(indices: IntRange): List<Byte> | ||
سطر 14: | سطر 14: | ||
fun CharArray.slice(indices: IntRange): List<Char> | fun CharArray.slice(indices: IntRange): List<Char> | ||
fun <T> List<T>.slice(indices: IntRange): List<T> | fun <T> List<T>.slice(indices: IntRange): List<T> | ||
− | </syntaxhighlight>يمكن تمرير كائن من النوع <code>Iterable</code> | + | </syntaxhighlight>أو يمكن تمرير كائن من النوع <code>Iterable</code> إلى الدالة <code>slice()</code> كوسيط:<nowiki/><nowiki/><syntaxhighlight lang="kotlin"> |
fun <T> Array<out T>.slice(indices: Iterable<Int>): List<T> | fun <T> Array<out T>.slice(indices: Iterable<Int>): List<T> | ||
fun ByteArray.slice(indices: Iterable<Int>): List<Byte> | fun ByteArray.slice(indices: Iterable<Int>): List<Byte> | ||
سطر 26: | سطر 26: | ||
fun <T> List<T>.slice(indices: Iterable<Int>): List<T> | fun <T> List<T>.slice(indices: Iterable<Int>): List<T> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | ==القيم | + | ==القيم المعادة== |
− | [[Kotlin/List| | + | تُعاد [[Kotlin/List|قائمة]] تحوي جزءًا من [[Kotlin/Array|المصفوفة]] أو [[Kotlin/List|القائمة]] <nowiki/>المعطاة يحدِّده الوسيط <code>indices</code> المعطى. |
==أمثلة== | ==أمثلة== | ||
− | + | <nowiki/><nowiki/>استعمال الدالة <code>()slice</code> لجلب جزء من مصفوفة يقع بين العنصر الثاني والخامس:<syntaxhighlight lang="kotlin"> | |
− | |||
fun main(args: Array<String>) { | fun main(args: Array<String>) { | ||
− | val array = arrayOf(1, 2, 3, 4, 5, 6) | + | val array = arrayOf(1, 2, 3, 4, 5, 6) |
− | + | ||
− | print (array.slice(1.. | + | print (array.slice(1..4)) // [2, 3, 4, 5] |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==انظر أيضًا== |
− | *<code>[[Kotlin/collections/sliceArray|sliceArray()]]</code> : | + | *الدالة <code>[[Kotlin/collections/sliceArray|sliceArray()]]</code> : تقطع جزءًا محدَّدًا من [[Kotlin/Array|المصفوفة]] التي استُدعيت معها ثمَّ تعيده في مصفوفة أو قائمة بحسب الوسيط الممرر إليها. |
+ | * التابع <code>[[Kotlin/Array/get|Array.get()]]</code>: تجلب قيمة العنصر في المصفوفة عند الفهرس المُحدَّد. | ||
+ | * الدالة <code>[[Kotlin/collections/indexOf|indexOf()]]</code>: تجلب فهرس أول ظهور لعنصر محدَّد من <nowiki/>[[Kotlin/Array|المصفوفة]] أو <nowiki/>[[Kotlin/collections|المجموعة]] أو القائمة التي استُدعيت معها. | ||
+ | * الخاصية <code>[[Kotlin/collections/indices|indices]]</code>: تجلب الفهارس الصحيحة (valid indices) للمصفوفة أو المجموعة (collection). | ||
==مصادر== | ==مصادر== | ||
− | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/slice.html الدالة | + | *[https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/slice.html صفحة الدالة slice() في التوثيق الرسميّ للمكتبة القياسيّة في لغة Kotlin.] |
[[تصنيف:Kotlin]] | [[تصنيف:Kotlin]] | ||
[[تصنيف:Kotlin Functions]] | [[تصنيف:Kotlin Functions]] |
مراجعة 16:53، 7 أغسطس 2018
تقطع الدالة slice()
جزءًا محدَّدًا من المصفوفة أو القائمة التي استُدعيت معها ثمَّ تعيده في قائمة.
البنية العامة
يمكن تمرير مجال محدَّد إلى الدالة slice()
كوسيط:
fun <T> Array<out T>.slice(indices: IntRange): List<T>
fun ByteArray.slice(indices: IntRange): List<Byte>
fun ShortArray.slice(indices: IntRange): List<Short>
fun IntArray.slice(indices: IntRange): List<Int>
fun LongArray.slice(indices: IntRange): List<Long>
fun FloatArray.slice(indices: IntRange): List<Float>
fun DoubleArray.slice(indices: IntRange): List<Double>
fun BooleanArray.slice(indices: IntRange): List<Boolean>
fun CharArray.slice(indices: IntRange): List<Char>
fun <T> List<T>.slice(indices: IntRange): List<T>
أو يمكن تمرير كائن من النوع Iterable
إلى الدالة slice()
كوسيط:
fun <T> Array<out T>.slice(indices: Iterable<Int>): List<T>
fun ByteArray.slice(indices: Iterable<Int>): List<Byte>
fun ShortArray.slice(indices: Iterable<Int>): List<Short>
fun IntArray.slice(indices: Iterable<Int>): List<Int>
fun LongArray.slice(indices: Iterable<Int>): List<Long>
fun FloatArray.slice(indices: Iterable<Int>): List<Float>
fun DoubleArray.slice(indices: Iterable<Int>): List<Double>
fun BooleanArray.slice(indices: Iterable<Int>): List<Boolean>
fun CharArray.slice(indices: Iterable<Int>): List<Char>
fun <T> List<T>.slice(indices: Iterable<Int>): List<T>
القيم المعادة
تُعاد قائمة تحوي جزءًا من المصفوفة أو القائمة المعطاة يحدِّده الوسيط indices
المعطى.
أمثلة
استعمال الدالة ()slice
لجلب جزء من مصفوفة يقع بين العنصر الثاني والخامس:
fun main(args: Array<String>) {
val array = arrayOf(1, 2, 3, 4, 5, 6)
print (array.slice(1..4)) // [2, 3, 4, 5]
}
انظر أيضًا
- الدالة
sliceArray()
: تقطع جزءًا محدَّدًا من المصفوفة التي استُدعيت معها ثمَّ تعيده في مصفوفة أو قائمة بحسب الوسيط الممرر إليها. - التابع
Array.get()
: تجلب قيمة العنصر في المصفوفة عند الفهرس المُحدَّد. - الدالة
indexOf()
: تجلب فهرس أول ظهور لعنصر محدَّد من المصفوفة أو المجموعة أو القائمة التي استُدعيت معها. - الخاصية
indices
: تجلب الفهارس الصحيحة (valid indices) للمصفوفة أو المجموعة (collection).