当前位置:网站首页>Day_ 16 set
Day_ 16 set
2022-06-25 16:26:00 【grp_ grp_ grp】
1. Array encapsulation
1.1 Adding, deleting, modifying and querying arrays
Inquire about
change
add to
Delete
1.2 Use
2. aggregate
Java A collection is a set of data that enables a program to store and manipulate elements that are not fixed .
2.1 Inheritance system
Collection Is a collection , The two direct sub interfaces are List and set
List characteristic : Orderly repeatable , Ensure that the data is added in the same order as the data is taken out
Set characteristic : disorder Do not repeat , There is no guarantee that the data is added and taken out in the same order
List There are three subcategories :
1. ArrayList : At the bottom is an array , Queries and changes are extremely efficient
2. LinkedList : The bottom layer is a two-way linked list , Adding and deleting are more efficient
3. Vector : The bottom layer is also an array , Is thread safe , obsolete , It is not recommended to use , Has been ArrayList Instead of
Set There are two subclasses :
1. HashSet : At the bottom is a hash table
2. TreeSet : At the bottom is a binary tree
2.3 Collection
Collection As the parent of the collection class , therefore ,collection The method in , Is a method that all collection classes have
Common methods :
Use
2.4 Iterator
Iterator iterator : An iterator is a pattern , It can separate the traversed object from the traversed object , We no longer care about the underlying data structure , How to store data? Just get the iterator object , You can traverse
collection in Provides a iterator() Method Used to get iterator objects aggregate .iterator();
In an iterator , There are three ways :
1 boolean hasNext() : Determine whether there are elements under the cursor , The default point is to the top , It doesn't point to the first element
2 E next() : Move the iterator cursor down one bit , And take out the element
3 remove () : Delete the currently executed element , Will also delete the in the set
Be careful :
Once the iterator is created , Collection cannot be added or deleted , If you add and delete , Need to regenerate iterators
enhance for loop forEach It's short for iterator
2.5 contains remove
contains(Object o) : Determine whether an element is included
remove(Object o ) : Deletes the specified element
These two methods , The bottom layer will call equals Methods for comparison
2.6 forEach
enhance for loop forEach It's short for iterator
2.7 List
2.7.1 ArrayList
List characteristic : Orderly repeatable , Ensure that the data is added in the same order as the data is taken out
List There are three subcategories :
1. ArrayList : At the bottom is an array , Queries and changes are extremely efficient , The default initialization capacity is 10, Expand to the original 1.5 times , Non-thread safety , When creating objects , No capacity , Namely 0 , When adding data for the first time , To initialize capacity
2.LinkedList : The bottom layer is a two-way linked list , Adding and deleting are more efficient
3. Vector : The bottom layer is also an array , Is thread safe , obsolete , It is not recommended to use , Has been ArrayList Instead of , The default initialization capacity is 10, Expand to the original 2 times
Be careful :
Only reference data types can be saved in a collection , If you add a basic type , Automatic packing will be carried out first to the corresponding packing class , Then polymorphic transformation occurs to Object type
usage :
边栏推荐
- Learning notes of rxjs takeuntil operator
- 教务系统开发(PHP+MySQL)
- AutoK3s v0.5.0 发布 延续简约和友好
- Principle analysis of ThreadLocal source code
- Navicat premium 15 for MAC (database development tool) Chinese version
- Catheon Gaming任命Activision Blizzard前亚太区负责人Mark Aubrey担任首席执行官
- Lecun predicts AgI: big model and reinforcement learning are both ramps! My "world model" is the new way
- Webgl and webgpu comparison [4] - uniform
- 【效率】又一款笔记神器开源了!
- Lifeifei's team applied vit to the robot, increased the maximum speed of planning reasoning by 512 times, and also cued hekaiming's MAE
猜你喜欢
随机推荐
Flutter textfield setting can input multiple lines
flutter
What are some tricks that novice programmers don't know?
Mt60b1g16hc-48b:a micron memory particles FBGA code d8bnk[easy to understand]
Uncover gaussdb (for redis): comprehensive comparison of CODIS
leetcode-8. String to integer (ATOI)
DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection翻译
DOM event flow, event delegate
Built in function globals() locals()
心楼:华为运动健康的七年筑造之旅
Bypass technology to talk about 'cross end'
Don't underestimate the integral mall, its role can be great!
Go language - lock operation
10 Super VIM plug-ins, I can't put them down
Uniapp converts graphic verification codes in the form of file streams into images
深入理解和把握数字经济的基本特征
绕过技术聊'跨端'......
Tensorflow loading cifar10 dataset
Educational administration system development (php+mysql)
普通人的2022春招总结(阿里、腾讯offer)