set的三种遍历方式,set遍历元素
2023-09-27 14:25:21 时间
package sun.rain.amazing.traversal; import java.util.*; /** * Created by sunRainAmazing on SUN_RAIN_AMAZING * @author sunRainAmazing */ public class TraversalSet { public static void main(String args[]){ List<String> list = new ArrayList<>( Arrays.asList("tom","cat","Jane","jerry")); Set<String> set = new HashSet<>(); set.addAll(list); //方法1 集合类的通用遍历方式, 从很早的版本就有, 用迭代器迭代 Iterator it1 = set.iterator(); while(it1.hasNext()){ System.out.println(it1.next()); } //方法2 集合类的通用遍历方式, 从很早的版本就有, 用迭代器迭代 for(Iterator it2 = set.iterator();it2.hasNext();){ System.out.println(it2.next()); } //方法3 增强型for循环遍历 for(String value: set){ System.out.println(value); } } }
相关文章
- Python集合(set)类型的操作
- python set集合是无需的,遍历也是无需的特别注意
- Redis 集合(Set)
- Java 集合List、Set、HashMap操作一(Array转List、Set排序、HashMap遍历、Set遍历、List遍历、HashMap大小长度、List打乱顺序)
- ES6 通过 set 和 map 实现对象数组去重
- 第七十四章 SQL命令 SET TRANSACTION
- oracle中SET DEFINE意思
- JS--Object、 Set、Map
- Java集合框架Set接口
- 【数据结构】Map和Set
- protobuf 中的嵌套消息的使用 主要对set_allocated_和mutable_的使用
- 使用MyEclipse建立working set
- java Map Set遍历
- Spring中xml文件配置也可以配置容器list、set、map
- 如何使用 Set 来提高JS代码的性能
- 关于字符集报错显示“255”Unknown initial character set index '255' received from server.
- Openstack部署总结:“部署过程Error: Local ip for ovs agent must be set when tunneling is enabled”问题
- redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set