当前位置:网站首页>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)]
}边栏推荐
- Openjudge noi 2.1 1752: chicken and rabbit in the same cage
- Niu Mei's mathematical problem --- combinatorial number
- Application of slip ring of shipborne radar antenna
- Blob 對象介紹
- Leetcode simple question: find the K beauty value of a number
- OpenVSCode云端IDE加入Rainbond一体化开发体系
- 探索STEAM艺术设计中的创造力
- Interactive book delivery - signed version of Oracle DBA work notes
- Uniapp mobile terminal forced update function
- 青龙面板-今日头条
猜你喜欢
随机推荐
Interview questions (CAS)
面试题(CAS)
Wang Zijian: is the NFT of Tencent magic core worth buying?
[untitled]
船载雷达天线滑环的使用
Complex network modeling (I)
复杂网络建模(一)
Unityhub cracking & unity cracking
积分商城管理系统中应包含的四大项
Lua 编程学习笔记
LeetCode简单题之找到一个数字的 K 美丽值
Leetcode medium question my schedule I
Content of string
力扣(LeetCode)187. 重复的DNA序列(2022.07.06)
在 Rainbond 中一键安装高可用 Nacos 集群
Vulnerability recurrence easy_ tornado
Myabtis_ Plus
Use of JMeter
电池、电机技术受到很大关注,反而电控技术却很少被提及?
B. Value sequence thinking









![[quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO](/img/56/82f4533b5bded73df222ef65101a72.png)