当前位置:网站首页>Collection collection overview
Collection collection overview
2022-07-22 10:15:00 【Hua Weiyun】
One : Collection Overview
What is the difference between a set and an array ?
An array is java A data structure in , The length of the data is fixed , Storage is linear . And can store basic data types and objects , Basic data objects can be boxed and stored according to basic types . Our array is of reference data type .
A set is java Another kind of data in i structure , Compared to arrays , Collections are more flexible . In terms of implementation , Collections are implemented in a variety of ways , It has a wide range of applications , The array adopts the method of continuous space allocation storage .
in addition , Collections take the form of classes and interfaces , have java Three characteristics of object-oriented , The comparison array more clearly reflects the object-oriented logical thinking .
java The set in is divided into single column set and double column set ,Collection Is the top-level interface of a single column set ,Map Is the top-level interface of a two column set . In terms of basic storage , The data stored in a single column only contains the data itself , Double columns contain keys and values , That is, double columns not only store the data itself , Also store the corresponding index . This article mainly introduces single column set Collection, And some sub interfaces below it .
Generally, we will learn these two basic List,Set, But actually , There is another kind. . This article will Collection All three interface implementation classes are described .
Two :Collection Set parsing
our JDK API That's right Collection General .
Collection hierarchy Root interface in .Collection Represents a set of objects , These objects are also called collection The elements of . some collection Duplicate elements are allowed , Others are not allowed to . some collection Is ordered , Others are disordered .JDK No direct access to this interface is provided Realization : It provides a more specific sub interface ( Such as Set and List) Realization . This interface is usually used to pass collection, And operate them where they need the most universality collection.
package (bag) Or more sets (multiset)( Unordered that may contain duplicate elements collection) This interface should be implemented directly .
All in common Collection Implementation class ( It is usually realized indirectly through one of its sub interfaces Collection) Two... Should be provided “ standard ” Construction method : One is void( No parameter ) Construction method , Used to create an empty collection; The other is with Collection The construction method of type single parameter , Used to create a new element with the same parameters collection. actually , The latter allows users to copy any collection, To generate an equivalent of the desired implementation type collection. Although this agreement cannot be enforced ( Because an interface cannot contain constructor ), however Java All common in the platform library Collection All implementations follow it .
**
The specific implementation interface class is mentioned here ,Set,List.
in addition , The document also professionally explains the following points that need to be paid attention to
Collections Framework Many methods in the interface are based on equals Method defined . for example ,contains(Object o) Method specification declaration :“ If and only if collection Contains at least one that satisfies (o==null ? e==null :o.equals(e)) The elements of e when , return true.” No This specification should be understood as implying that the call has non null parameters o Of Collection.contains Method will result in arbitrary e Element call o.equals(e) Method . Various implementations can be optimized at will , Just avoid calling equals that will do , for example , By first comparing the hash codes of the two elements .(Object.hashCode() The specification guarantees that two objects with unequal hash codes will not be equal ). More commonly , Various Collections Framework The implementation of the interface can use the bottom layer at will Object The specified behavior of the method , Regardless of whether the implementation program thinks it's appropriate .
It is embodied in its implementation interface class , Explain in detail later in the article
Collection Itself provides some of its own methods
Extract common methods
1. Add functionality boolean add(E e) Add an element boolean addAll(Collection c) Add a batch of elements 2. Delete function boolean remove(Object o) Delete an element 3. Judgment function boolean contains(Object o) Determines whether the collection contains the specified element boolean isEmpty() Determines if the set is empty ( There are no elements in the collection )4. Acquisition function int size() Get the length of the collection 5. Conversion function Object[] toArray() Convert a set to an array
边栏推荐
- Share a go auxiliary command line
- Rhcsa browsing common file usage, use of grep, cut, uniq, sort, TR commands
- Equal principal increasing repayment / equal principal decreasing mortgage repayment calculator
- When the easycvr platform cascades, there is an error prompt. What is the reason why the port is unreachable?
- 将瑞吉外卖项目jar包部署在远程服务器并成功运行在pc和移动端
- Rhcsa compression also includes decompression, tar archive command, file upload and download, variables in sehll, command alias, and command history
- 使用cpolar建立一个商业网站(3)
- 软件测试过程的持续改进
- Crazy God redis notes 07
- Use of rhcsa simple commands (LS, date, timedatectl, file, STAT), file type
猜你喜欢
高度关注,2022开放原子开源峰会最新议程一览
Equal principal increasing repayment / equal principal decreasing mortgage repayment calculator
Read the paper with me - multi model text recognition network
First meet JS
HD06-ASEMI贴片整流桥HD06
SQLite in the flutter tutorial_ Wrapper new dart and shutter libraries for SQLite
Asemi rectifier bridge lb10s parameters, lb10s characteristics, lb10s mechanical data
CNN的一些可视化方法
那些测试员面试中的“潜规则”,千万不要踩坑
openEuler志高远,开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛即将开幕
随机推荐
Rollup is layer2 battle: issue tokens to compete for the market
HCIP(10)
简单的一个盒子移动到另一个盒子,你用什么方式实现动画效果
[error reporting] valueerror: it seems that you are using the keras 2 and you are passing both
Kotlin prints error messages and uploads the error messages to the server
Service & Endpoint
How to quickly develop a simple and practical MES system?
SQLite in the flutter tutorial_ Wrapper new dart and shutter libraries for SQLite
简单弄懂Saas是什么? Saas与传统软件有什么区别?
指针的理解与操作
测试员官方承认的“五个等级”,来看看你处于哪个阶段?
Asemi rectifier bridge lb10s parameters, lb10s characteristics, lb10s mechanical data
How to efficiently backup local data to Tencent cloud
Understanding of web standards and W3C?
openEuler志高远,开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛即将开幕
仅需3 小时,如何用 AI 做场景贴图,完成场景制作 ?AI创作工作流探索
Basic concept of MySQL database and deployment of MySQL version 8.0 (I)
基于卡尔曼滤波的微电网调度(Matlab代码实现)
Why are there career bottlenecks for test / development programmers? It seems that everything has changed
Use of rhcsa simple commands (LS, date, timedatectl, file, STAT), file type