JAVA集合

Set集合

一、感性认知:

1、对比List集合来看Set集合,感受差异化,想象距离任意情景,比较何时用List集合,何时用 Set集合。

二、理性认知:

1、集合结构图

a、java.util.Collection[I]

java.util.List[I]

java.util.ArrayList[C]

java.util.LinkedList[C]

java.util.Vector[C]

java.util.Stack[C]

java.util.Set[I]

java.util.HashSet[C]

LinkedHashSet[C]

java.util.SortedSet[I]

java.util.NavigableSet[I]

java.util.TreeSet[C]

java.util.Map[I]

java.util.SortedMap[I]

java.util.TreeMap[C]

java.util.HashTable[C]

java.util.HashMap[C]

java.util.LinkedHashMap[C]

java.util.WeakHashMap[C]

2、Set集合的存储特点

a、Set集合内部使用Map集合来存储。

b、HashSet集合,元素具有互斥性。(用代码举例)

c、HashSet集合,元素插入存储的顺序和遍历访问的数序,是不一致的。即,无序性。

e、TreeSet集合,存储其中的元素会按照compareTo比较出来的结果进行排序。

e.1、无序性:插入顺序和存储顺序不一定一致。

e.2、有序性:该集合中的元素均按照升序排列。

e.3、互斥性,与HashSet相同。

f、LinkedHashSet集合,继承自HashSet

f.1、有序性:元素的访问可以按照插入的顺序进行访问。

f.2、无序性:元素的存储顺序并不一定按照插入的顺序进行。

(PS:通过链表实现插入顺序和实际存储下标的唯一映射)

3、HashSet与LinkedHashSet比较:

a、HashSet:添加元素快。

b、LinkedHashSet:添加元素慢

(PS:LinkedHashSet额外维护了一个插入顺序的链表,消耗更多。)

4、Iterator:

即Set集合的遍历,Interator it = set.iterator();

与List集合的迭代器遍历相似。

5、Iterator与ListIterator比较:

a、前者:提供集合的迭代方法,hasNext(),next(),remove();

b、后者:提供向前向后的迭代方法,还可以返回迭代时的下标索引。

提供添加元素的方法,将元素添加至当前指针所指向的位置。

提供设置元素的方法,将当前指针所指向的位置的元素设置为指定值。

6、TreeSet排序原理:

使用CompareTo方法进行排序,如果是自定义类,那么需要让该类实现Comparable接口

如果欲实现按照某个数据升序排序TreeSet集合中的对象,那么使用:

this.field - obj.field(升序)

obj.field - this.field(降序)

7、HashSet去重原理:

a、判断添加元素的HashCode是否相同。

b、判断添加元素的equals是否相同。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VhdManager.exe VhdManager.ini ; Generated (13.09.2015 18:44:54) by Simple Vhd Manager v1.0 ; www.sordum.org [Main] Language=Auto WinSetOnTop=0 GridLines=1 NewVhdSize=2,5 NewVhdOpt=0 [VirtualDiskFiles] 1=C:\20180619_034757.vhd [Language_English] 01="BlueLife" 02="Attach marked and detach unmarked files" 03="Add file to list" 04="Remove file from list" 05="Refresh list" 06="Disk Management" 07="Action\n Location\n Attached\n Boot Menu\n Virtual Size" 08="&File;\n &Edit;\n &Options;\n Tools \n &Help;" 09="&Add; File" 10="&Create; and Attach VHD" 11="&Attach; Marked Files" 12="&Detach; All Files" 13="&Remove; Entries In Boot Menu" 14="&Exit;" 15="&Attach;" 16="&Detach;" 17="&Read;-Only" 18="&Add; to Boot Menu" 19="&Remove; From Boot Menu" 20="&Paste; File" 21="&Remove;" 22="&Remove; All" 23="&Check; - Uncheck" 24="&Check; All" 25="&Uncheck; All" 26="&Open; Location" 27="&File; Properties" 28="&Disk;" 29="&Cd;-Rom" 30="&Refresh;" 31="&Open; With Explorer" 32="&Change; Drive Letter" 33="&Remove; Letter" 34="&Drive; Properties" 35="&Attach; Marked To System Startup" 36="&Disable; Autorun" 37="&Always; On Top" 38="&Show; Grid Lines" 39="&Add; to Context Menu" 40="&Show; Hidden Files" 41="&Show; File Extensions" 42="Disk &Management;" 43="Diskpart &Command; Prompt" 44="&Msconfig;" 45="&Restart; Windows Explorer" 46="&Donate;" 47="&HomePage;" 48="&Contact;" 49="&About;" 50="Please Wait ..." 51="Select Virtual Disk File\n Virtual Disk Files\n All Files" 52="Enter boot menu name\nOk\nCancel" 53="Added" 54="Unable to write file!" 55="File not found!" 56="The file path must not contain any spaces. Please correct it and try again." 57="Virtual hard disk size \nVirtual hard disk format \n Virtual hard disk type \nDynamically expanding \n Fixed" 58="%drive% not enough free space!\n Do you wish to continue?" 59="An error occurred. Check your settings and try again! \nError Code:%error%" 60="Mount &Options;\n &Mount; \n &Unmount; \n &Open; With Simple VHD Manager\n VHD Mount \n V

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值