Kotlin containsAll用法及代码示例

本文方法及代码示例基于Kotlin 2.1.20 Released

containsAll 所在包 kotlin.collections.containsAll,其相关用法介绍如下:

用法:

kotlin 复制代码
fun <T> Collection<T>.containsAll(
    elements: Collection<T>
): Boolean

检查指定集合中的所有元素是否都包含在此集合中。

允许克服需要传递类型为 Collection<E> 的集合的 containsAll 的 type-safety 限制。

代码示例:

kotlin 复制代码
import kotlin.test.*

fun main(args: Array<String>) {
    //sampleStart
    val collection = mutableListOf('a', 'b')
    val test = listOf('a', 'b', 'c')
    println("collection.containsAll(test) is ${collection.containsAll(test)}") // false

    collection.add('c')
    println("collection.containsAll(test) is ${collection.containsAll(test)}") // true
    //sampleEnd
}

// 输出
collection.containsAll(test) is false
collection.containsAll(test) is true

相关方法

相关推荐
冠希陈、20 小时前
PHP 判断是否是移动端,更新鸿蒙系统
android·开发语言·php
晚霞的不甘1 天前
Flutter for OpenHarmony从零到一:构建《冰火人》双人合作闯关游戏
android·flutter·游戏·前端框架·全文检索·交互
2601_949833391 天前
flutter_for_openharmony口腔护理app实战+饮食记录实现
android·javascript·flutter
独自破碎E1 天前
【滑动窗口+字符计数数组】LCR_014_字符串的排列
android·java·开发语言
stevenzqzq1 天前
compose 中 align和Arrangement的区别
android·compose
VincentWei951 天前
Compose:MutableState 和 mutableStateOf
android
jian110581 天前
Android studio配置flutter,mac Android studio 发现苹果手机设备
android·flutter·android studio
2501_940007891 天前
Flutter for OpenHarmony三国杀攻略App实战 - 性能优化与最佳实践
android·flutter·性能优化
Rysxt_1 天前
UniApp获取安卓系统权限教程
android·uni-app
毕设源码-朱学姐1 天前
【开题答辩全过程】以 基于安卓的教师上课辅助系统为例,包含答辩的问题和答案
android