当前位置:网站首页>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)]
}
边栏推荐
- eBPF Cilium实战(2) - 底层网络可观测性
- UnityHub破解&Unity破解
- 青龙面板-今日头条
- 贝叶斯定律
- Linux Installation MySQL 8.0 configuration
- Excel import function of jeesite form page
- Topic not received? Try this
- [quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)
- Zcmu--1396: queue problem (2)
- Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
猜你喜欢
opencv学习笔记三——图像平滑/去噪处理
解读创客思维与数学课程的实际运用
通俗易懂单点登录SSO
解析创新教育体系中的创客教育
Register of assembly language by Wang Shuang
Unityhub cracking & unity cracking
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
LeetCode简单题之字符串中最大的 3 位相同数字
Easy to understand SSO
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
随机推荐
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
Complete linear regression manually based on pytoch framework
eBPF Cilium实战(1) - 基于团队的网络隔离
拓维信息使用 Rainbond 的云原生落地实践
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
[untitled]
Merging binary trees by recursion
Wang Zijian: is the NFT of Tencent magic core worth buying?
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
王爽 《汇编语言》之寄存器
Empire CMS collection Empire template program general
Example of file segmentation
Recursive method to construct binary tree from preorder and inorder traversal sequence
JS quick start (I)
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)
JS copy picture to clipboard read clipboard
Find the mode in the binary search tree (use medium order traversal as an ordered array)
B. Value sequence thinking
Pytoch (VI) -- model tuning tricks
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne