当前位置:网站首页>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);
}
}
}

边栏推荐
- laravel 2020-01-01T00:00:00.000000Z 日期转化
- [learn FPGA programming from scratch -17]: quick start chapter - operation steps 2-5- VerilogHDL hardware description language symbol system and program framework (both software programmers and hardwa
- leetcode785. 判断二分图(中等)
- If you want to learn ArrayList well, it is enough to read this article
- Nat Commun|语言模型可以学习复杂的分子分布
- 【剑指Offer】21.调整数组顺序使奇数位于偶数前面
- Nat commun | language model can learn complex molecular distribution
- MySQL quick start instance (no loss)
- Step 4 of installation in RF: an error is reported when installing the robotframework-selenium 2library
- 最近7天,最近10天,最近90天时间处理逻辑
猜你喜欢

How the autorunner automated test tool creates a project -alltesting | Zezhong cloud test

Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation

Elk enterprise log analysis system

MySQL quick start instance (no loss)

leetcode417. Pacific Atlantic current problems (medium)

Pytest test framework Basics

瑞吉外卖项目(三)员工管理业务开发

Deep separable convolution

什么是泛型?为什么要使用泛型?泛型怎么用?那包装类呢?

Code farming essential SQL tuning (Part 1)
随机推荐
Data enhancement
postgresql创建表
(湖南科技大学oj作业)问题 G: 串的模式匹配
DHCP protocol instantiation analysis
leetcode-141. Circular linked list
rf中安装的第四步:安装 robotframework-selenium2library报错
Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation
What if the win10 security center cannot be closed
Database resource load management (Part 2)
High concurrency pseudo sharing and cache line filling (cache line alignment) (@contained)
Memory optimization table mot management
Laravel 2020-01-01t00:00:00.000000z date conversion
Cloud data management will break the island of storage and the island of team
The flat life of older farmers from Beijing to Holland
再聊数据中心网络
postgresql创建数据库
Db4ai: database driven AI
Will you be punished for not wearing seat belts in the back row?
整了20张高清数据分析全知识地图,强烈建议收藏!
基于FPGA的VGA协议实现