当前位置:网站首页>Differences between list and set access elements
Differences between list and set access elements
2022-06-11 16:18:00 【zhangsan3333】

Collection aggregate ( Interface ) Under the interface of 2 A direct sub interface :
List aggregate ( Interface ):
You can save duplicate elements , Have subscript , Storage order , Can store multiple null Elements .ArrayList class : The bottom layer is a variable array , Operate according to the subscript , Fast query efficiency , The efficiency of addition and deletion is low .
LinkedList class : At the bottom is the list , Operate according to the head and tail of the linked list , Fast addition and deletion efficiency , Query efficiency is low .
Set aggregate ( Interface ):
Cannot save duplicate elements , No subscript . Can be stored null But only one . And the order of access is not guaranteed, That is, for sets set There is no order when accessing , There is no law .
package SetTest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Set3 {
public static void main(String[] args) {
Set<String> set = new HashSet();
set.add("c");
set.add("b");
set.add("a");
set.add("a");
set.add(null);
set.add(null);
for (String s1 : set) {
System.out.println("s1 = " + s1);
}
System.out.println();
List<String> list = new ArrayList<>();
list.add("c");
list.add("b");
list.add("a");
list.add("a");
list.add(null);
list.add(null);
for (String s2 : list) {
System.out.println("s2 = " + s2);
}
}
}

边栏推荐
- Can I eat meat during weight loss? Will you get fat?
- Toolbar details of user interface - autorunner automated test tool
- What is RS stamp paper?
- 减肥期间可以吃肉吗?会胖吗?
- 问题 AC: 中国象棋中的跳马问题
- 项目经理如何击退被工作汇报支配的恐惧感?
- 基于ssm框架实现的企业进销存管理系统【源码+数据库+毕设】
- Laravel listening mode
- Step 4 of installation in RF: an error is reported when installing the robotframework-selenium 2library
- MySQL快速入门实例篇(入内不亏)
猜你喜欢

postgresql启动过程

再聊数据中心网络

推开混合云市场大门,Lenovo xCloud的破局之道

leetcode417. 太平洋大西洋水流问题(中等)

【剑指Offer】22.链表中倒数第K节点

AI tool for cutting-edge technology exploration: analog detection

What is a generic? Why use generics? How do I use generics? What about packaging?

1267_FreeRTOS启动第一个任务接口prvPortStartFirstTask实现分析

MySQL快速入门实例篇(入内不亏)
![[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers](/img/ba/8fa84520bacbc56ce7cbe02ee696c8.png)
[sword finger offer] 21 Adjust array order so that odd numbers precede even numbers
随机推荐
再聊数据中心网络
Opengauss AI capability upgrade to create a new AI native database
MSDN download win11 method, simple and easy to operate
真香,华为主动离职也给 N+1
This "invisible" robot may be your future colleague
Opengauss version 3.0.0 was officially released, and immediately experience the first lightweight version in the community
C# 启动一个外部exe文件,并传入参数
电脑下面的任务栏怎么显示打开的程序
Opengauss enterprise installation
Question ac: Horse Vaulting in Chinese chess
收藏 | 可解释机器学习发展和常见方法!
Aaai2022 latest "time series data processing" report, 127 pages of PPT describing time series data processing and medical application progress
AI tool for cutting-edge technology exploration: analog detection
laravel8 实现签到功能案例
Nat Commun|語言模型可以學習複雜的分子分布
面试高频算法题---最长回文子串
leetcode463. 岛屿的周长(简单)
Laravel 2020-01-01t00:00:00.000000z date conversion
如何优化 Compose 的性能?通过「底层原理」寻找答案 | 开发者说·DTalk
1267_ FreeRTOS starts the first task interface prvportstartfirsttask implementation analysis