zip
所在位置是kotlin.text.zip
,其相關用法介紹如下。
用法一
返回由具有相同索引的this
和other 字符序列的字符構建的對列表。返回的列表具有最短字符序列的長度。
例子:
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringA = "abcd"
val stringB = "zyx"
println(stringA zip stringB) // [(a, z), (b, y), (c, x)]
//sampleEnd
}
輸出:
[(a, z), (b, y), (c, x)]
用法二
使用提供的適用於每對字符的 transform 函數,返回由 this
和具有相同索引的 other 字符序列的字符構建的值列表。返回的列表具有最短字符序列的長度。
例子:
import java.util.Locale
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val stringA = "abcd"
val stringB = "zyx"
val result = stringA.zip(stringB) { a, b -> "$a$b" }
println(result) // [az, by, cx]
//sampleEnd
}
輸出:
[az, by, cx]
相關用法
- Kotlin zip用法及代碼示例
- Kotlin zipWithNext用法及代碼示例
- Kotlin associateBy用法及代碼示例
- Kotlin all用法及代碼示例
- Kotlin map用法及代碼示例
- Kotlin filterNot用法及代碼示例
- Kotlin reduceRight用法及代碼示例
- Kotlin Random.Default用法及代碼示例
- Kotlin Byte.inc用法及代碼示例
- Kotlin getValue用法及代碼示例
- Kotlin Double.dec用法及代碼示例
- Kotlin windowedSequence用法及代碼示例
- Kotlin contentToString用法及代碼示例
- Kotlin groupByTo用法及代碼示例
- Kotlin commonPrefixWith用法及代碼示例
- Kotlin MatchResult.Destructured用法及代碼示例
- Kotlin Delegates.notNull用法及代碼示例
- Kotlin ifBlank用法及代碼示例
- Kotlin filterNotTo用法及代碼示例
- Kotlin getOrPut用法及代碼示例
- Kotlin Triple.<init>用法及代碼示例
- Kotlin Duration.toString用法及代碼示例
- Kotlin windowed用法及代碼示例
- Kotlin indexOf用法及代碼示例
- Kotlin reduceIndexed用法及代碼示例
注:本文由純淨天空篩選整理自kotlinlang.org大神的英文原創作品 kotlin.text.zip。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。