Kotlin 1.9.10 官方文档 中文版
void listToSet() { var sourceList = List.of(1, 2, 3, 1); var copySet = Set.copyOf(sourceList); System.out.println(copySet); } In Kotlin, use the function toSet() : fun main() { //sampleStart //sampleStart // Kotlin val sourceList = listOf(1, 2, 3, 1) val copySet = sourceList.toSet() println(copySet) //sampleEnd } 元素分组 In Java, you can group elements with the Collectors function val sourceList = mutableListOf(1, 2, 3) val copySet = sourceList.toMutableSet() copySet.add(3) copySet.add(4) println(copySet) //sampleEnd } 或者,可以创建对同一集合实例的新引用。使用现有集合初始化集合变量时,0 码力 | 3753 页 | 29.69 MB | 1 年前3
共 1 条
- 1













