Set是Collection的子接口,用来存储无序的,不可重复的数据
不是随机性,因为他是按照hashCode顺序保存,也是有一定规律的。只不过不是按照添加的顺序。
hashSet存储时 先计算出hashcode然后取模存储到指定位置,如果有第二个数据存储到同一个位置这时会比较他们的equals,如果过相同则不会存入,不同的话会在位置上生成一个链表存储取模一致的数据。
无序性和添加元素的位置有关,不像是ArrayList一样按照添加顺序依次紧密排列,
添加到Set中的数据不能是相同的,比较的标准是比较HashCode,与equals比较的结构。
相较于List、Map。这个Set使用场景比较少。
主要用来过滤重复数据
常用方法即为Collection中定义的15个方法,由于没有索引减少了很多操作。
添加到HashSet或者LinkedHashSet的要求:
元素所在的类要重写equals方法和hashCode方法要保持一致性,使用idea自动生成就好
推荐阅读:
vue.js:634 [Vue warn]: Property or method "userName" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See:
状态码:415,发送HTTP请求返回415状态码的解决办法
SpringBoot 整合 webapp时 访问404的解决办法
Vue 打开页面时就加载方法,例如查询
SpringCloud怎么调用多个服务的信息
Spring整合Mybatis
SpringCloud 加入 thymleaf前端页面的方法
Controller之间的跳转
This may be the result of an unspecified view, due to default view name generation
Spring AOP的实现原理
行动消除疑虑