当前位置:网站首页>List interface three sub implementation classes
List interface three sub implementation classes
2022-06-23 08:18:00 【Liang FuFu】
1. List Three sub implementation classes
1.1 List Set three sub implementation class characteristics
1.ArrayList: It is our common , In a single threaded program , The highest efficiency of execution .(List Set default use )
The underlying structure is an array structure : Quick query , Add or delete slowly .
Is a thread unsafe class , Out of sync .
2.Vector: The underlying data structure is also an array , Quick query , Add or delete slowly
Is a thread safe class , Sync , Inefficient execution
3.LinkedList: The underlying data structure is a linked list : Slow query , Additions and deletions quickly
Thread unsafe class , Efficient
1.2 Vector aggregate
1. Unique features :
public void addElement(E obj): stay Vector Add a new element to the end of the collection
public E elementAt(int index): Get the element at the specified location
public Enumeration<E> elements(): It's like an iterator , Unique method
Enumeration Interface
boolean hasMoreElements(): Whether there are more components ( Elements ) Traversable
E nextElement(): Get next element
2.Vector There are two more traversals
public E elementAt(int index) and size() Methods combined with common for
example :for(int x=0;x<Vector.size();x++){
String s = Vector.elementAt(x);
sout(s);
}
public Enumeration<E> elements():Vector The unique iterator operation of
boolean hasMoreElements(): Whether there are more components ( Elements ) Traversable
E nextElement(): Get next element
example :Enumeration<String> enumeration = Vector.elements();
while(enumeration.hasMoreElements()){
String s = enumeration.nextElement();
System.out.println(s);
}
1.3 LinkedList aggregate
1. Unique features :public void addFirst(Object e): Add any type of element to the beginning of the linked list every time
public void addLast(Objet e): Every time an element of any type is conditioned to the end of the linked list
public Object removeFirst() Remove and return the first element from this list .
public Object removeLast() Delete from this list and return the last element
public Object getFirst(): Get the first element of the linked list
public Object getLast(): Get the last element of the linked list
2. utilize LinkedList Realize stack function
public class MyStack{
private LinkedList list;
public MyStack(){
list = new LinkedList<>;
}
public void add(Object obj){
list.addFirst(obj);
}
public Object get(){
return list.removeFirst();
}
public boolean isEmpty(){
return link.isEmpty();
}
}
public class Test{
main();
MyStack mystack = new MyStack();
mystack.add("hello");
mystack.add("world");
mystack.add("javaee");
while(!MyStack.isEmpty()){
Object o = mystack.get();
sout(o);
}
}
边栏推荐
猜你喜欢
随机推荐
How to start Jupiter notebook in CONDA virtual environment
Implementation principle and source code analysis of ThreadPoolExecutor thread pool
5本财富自由好书的精华
Go 数据类型篇(二)之Go 支持的数据类型概述及布尔类型
复选框的基本使用与实现全选和反选功能
Apache Solr arbitrary file read replication
5-旋转的小菊-旋转画布和定时器
81 sentences worth repeating
Generate code 39 extension code in batch through Excel file
GTEST死亡测试
After easynvr video is enabled, no video file is generated. How to solve this problem?
谈谈 @Autowired 的实现原理
Openvino series 19 Openvino and paddleocr for real-time video OCR processing
Jetpack family - ViewModel
How can easycvr access the Dahua CVS video recorder and download a video file with an empty name?
9 ways in which network security may change in 2022
Copy image bitmap by C # memory method
How to migrate x86 architecture applications to arm architecture at low cost
The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?
Code quality level 3 - readable code









