004_swift_set 集合
2023-09-27 14:27:38 时间
//
// main.swift
// 004_集合
//
// Created by liuan on 2020/3/22.
// Copyright © 2020 liuan. All rights reserved.
//
import Foundation
//集合
//特点。无序 不重复
var set1:Set<Int>=[1,2,3,4,5]
var set2=[1,2,3,3,5]
print(set1,set2);
//操作
//集合的总数
let count=set1.count;
print(count)
//判断是否为空
let ret1=set1.isEmpty
//是否包含某个元素
let ret2=set1.contains(3)
//遍历
for ele in set1{
print(ele)
}
//集合最值
let min=set1.min();
let max=set1.max();
//插入元素
set1.insert(5);
//删除元素
set1.remove(1);
set1.removeFirst();
//set1.removeAll();
//数学运算(交集 intersection 补集 union 并集 subtracting)
let set3=set1.intersection(set2);
print(set3)
let set4=set1.union(set2)
print(set4)
let set5=set1.subtracting(set2);
print(set5)
效果展示
[2, 5, 1, 3, 4] [1, 2, 3, 3, 5]
5
2
5
1
3
4
[5, 3]
[2, 5, 1, 3, 4]
[4]
相关文章
- Leetcode: Set Matrix Zeroes
- Java中集合List,Map和Set的差别
- python set集合是无需的,遍历也是无需的特别注意
- 报错:Hadoop Warning: fs.defaultFS is not set when running "ls" command.
- Java 集合List、Set、HashMap操作一(Array转List、Set排序、HashMap遍历、Set遍历、List遍历、HashMap大小长度、List打乱顺序)
- Matlab中set函数的使用
- set的相关习题
- spring中List,Set,Map集合的输出(详解)
- s5pv210启动debian出错提示bash: cannot set terminal process group (-1): Inappropriate ioctl for device
- 第49节:Java集合框架中底层文档的List与Set
- STL - 容器 - Set
- python 集合set的创建和常见操作
- 【linux】解决Couldn‘t find a valid ICU package installed on the system. Set the configuration flag Syste
- Java中集合Set的用法
- 集合set对象
- VI :set noautoindent
- 判断List、Map、Set是否为空及效率比较
- sublimetext的文件编码理解reopen/reload with encoding,set encoding,save with encoding, set file encoding to
- java中 set,list,array(集合与数组)相互转换
- Python学习---Python下[set集合]的学习
- Python学习---列表/元组/字典/字符串/set集合/深浅拷贝1207【all】
- rman中 Backup Set 与 Image Copy 优缺点比较
- set names utf8;
- UVA 11294 - Wedding(Two-Set)
- Java -- 容器使用 Set, List, Map, Queue
- 'hibernate.dialect' must be set when no Connection available
- 【java读书笔记】——Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)
- Shell初学(八)linux下的ACL,linux特殊权限set uid
- Java集合框架学习(ArrayList、Set、Collection、Vector、Enumeration、Map、Iterator)
- Java list、map、set、vector集合类型中的null值