当前位置:网站首页>Kotlin combines flatmap for filtering and zip merge operators
Kotlin combines flatmap for filtering and zip merge operators
2022-07-07 08:15:00 【yu-Knight】
//Kotlin Combination of Chinese and Western Medicine flatMap Perform filtering operations and zip Merge operators
fun main() {
val list = listOf<String>(" Huang Xiaoming ", " Jet Li ", " Bruce Lee ", " Liu Jun ", " Li Si ", " Liu Ming ", " Liu Jun ", " Huangjiaju ", " huang feihong ")
val list2 = list.map {
"$it"
}
println(list2)
val newList = listOf(
listOf(" Huang Xiaoming ", " Jet Li ", " Bruce Lee "),
listOf(" Liu Jun ", " Li Si ", " Liu Ming "),
listOf(" Liu Jun ", " Huangjiaju ", " huang feihong ")
)
newList.flatMap { it ->
it.filter { it ->
it.contains(" yellow ") // Inside is true Just go back to ,false Just filter it out. Don't
}
}.map {
println("$it ")
}
/*******************************************/
val names = listOf(" Zhang San ", " Li Si ", " Wang Wu ")
val ages = listOf(12, 34, 22)
// principle : Put the first set and the second set , combined , Create a new collection and return
// Create a new collection ( Elements , Elements , Elements ) Elements Pair(K,V) K Replace the elements in the first set ,V Represents the elements in the second set
val zip: List<Pair<String, Int>> = names.zip(ages)
println(zip) //[( Zhang San , 12), ( Li Si , 34), ( Wang Wu , 22)]
}
边栏推荐
- Blob 對象介紹
- Application of slip ring of shipborne radar antenna
- 解析创新教育体系中的创客教育
- Fast parsing intranet penetration escorts the document encryption industry
- Game attack and defense world reverse
- Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
- Full text query classification
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- opencv学习笔记三——图像平滑/去噪处理
- buureservewp(2)
猜你喜欢
Easy to understand SSO
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Niu Mei's mathematical problem --- combinatorial number
Content of string
The largest 3 same digits in the string of leetcode simple question
解析机器人科技发展观对社会研究论
让Livelink初始Pose与动捕演员一致
Codeforce c.strange test and acwing
追风赶月莫停留,平芜尽处是春山
随机推荐
DNS server configuration
Basic use of CTF web shrink template injection nmap
电池、电机技术受到很大关注,反而电控技术却很少被提及?
海信电视开启开发者模式
Recursive construction of maximum binary tree
在Rainbond中实现数据库结构自动化升级
Example of file segmentation
buureservewp(2)
LeetCode简单题之找到一个数字的 K 美丽值
数据库实时同步利器——CDC(变化数据捕获技术)
Excel import function of jeesite form page
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Leetcode simple question: find the K beauty value of a number
JS复制图片到剪切板 读取剪切板
利用 Helm 在各类 Kubernetes 中安装 Rainbond
Wang Zijian: is the NFT of Tencent magic core worth buying?
Myabtis_Plus
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
Leetcode medium question my schedule I
Real time monitoring of dog walking and rope pulling AI recognition helps smart city