java中HashSet和LinkedHashSet
来源:互联网 发布:淘宝查询买家退货率 编辑:程序博客网 时间:2024/06/06 00:53
HashSet: 内部使用hashMap存储
HashSet: 加入时无序,输出也是无序,并且是线程不同步。
需要实现Collections.synchronizedSet(new HashSet(...))来实现线程同步:
LinkedHashSet:按照加入的顺序迭代;线程不同步。
package ray.com;import java.util.HashSet;import java.util.LinkedHashSet;import java.util.Set;import ray.tools.Print;public class TestSet {public static void main(String[] args) {System.out.println("hashSet-----------------------");TestHashSet();System.out.println("linkedHashSet----------------");TestLinkHashSet();}// Linked:有序存储private static void TestLinkHashSet() {Set<Integer> set = new LinkedHashSet<Integer>();for (int i = 0; i <= 10; i++) {set.add(i);}Print.PrintSet(set);}// 无序存储private static void TestHashSet() {Set<String> set = new HashSet<String>();set.add("1");set.add("11");set.add("1111");set.add("11111");Print.PrintSet(set);}}
hashSet-----------------------111111111111linkedHashSet----------------012345678910
0 0
- java中HashSet和LinkedHashSet
- Java中HashSet、LinkedHashSet和TreeSet的使用
- Java HashSet和LinkedHashSet的用法
- 深入探索Java-HashSet和LinkedHashSet
- Java HashSet和LinkedHashSet的用法
- java源码分析之HashSet和LinkedHashSet
- Java HashSet和LinkedHashSet的用法
- Java集合之HashSet和LinkedHashSet
- Java容器HashSet和LinkedHashSet源代码解析
- 【Java源码】HashSet、LinkedHashSet
- Java-HashSet/LinkedHashSet整理
- HashSet、LinkedHashSet和TreeSet
- HashSet、TreeSet和LinkedHashSet
- HashSet、LinkedHashSet和TreeSet
- TreeSet,HashSet和LinkedHashSet
- HashSet,LinkedHashSet和TreeSet
- HashSet,TreeSet和LinkedHashSet
- HashSet和LinkedHashSet练习
- 小试讯飞语音的听写功能
- pcl点云PCD文件
- androidStudio出现Executing tasks: [:app:assembleDebug]等错误不能运行程序
- 用Golang写一个搜索引擎(0x02)
- mysql用户权限相关
- java中HashSet和LinkedHashSet
- mysql修改root密码
- C语言模拟php basename() 函数
- 三种定时器的使用
- 排序算法系列:Shell 排序算法
- SQLServer 2008自动备份数据库
- [温故而知新] 《深度探索c++对象模型》——运行期语意
- SQLServer数据库备份(语句方式)
- Python - cannot import OpenCV module?