Deque, Queue and Stack in java

java is defined in Java. The util.Queueinterface is used to represent queues. Queue in Java belongs to the same level interface as List and Set, they all inherit from CollectionInterface. Java also defines a double-ended queue java.util.Deque, our commonly used LinkedList is implemented Dequeinterface. From the above figure we can know that “Queue has a direct subclass PriorityQueue” and Deque has two direct subclasses “LinkedList and ArrayDeque”. public interface Queue extends Collection {boolean add(E e);boolean offer(E e);E remove();E poll();E element() ;E peek();} public interface Deque extends Queue {void addFirst(E e);void addLast(E e); boolean offerFirst(E e);boolean offerLast(E e);E removeFirst();E removeLast();E pollFirst();E pollLast();E getFirst();E getLast();E peekFirst();E peekLast();boolean removeFirstOccurrence(Object o);boolean removeLastOccurrence(Object o);// *** Queue methods ***boolean add(E e);boolean offer(E e);E remove();E poll( );E element();E peek();// *** Stack methods ***void push(E e);E pop();// *** Collection methods ***boolean remove(Object o) ;boolean contains(Object o);public int size();Iterator iterator();Iterator descendingIterator();} From the official explanation&#xff0c ;ArrayDeque is a double-ended queue with no initial capacity; LinkedList is a two-way linked list. And we can also see that “ArrayDeque is more efficient than LinkedList when used as a queue” and in the stack usage scenario, “LinkedList, which has a tail node that does not need to be empty, is undoubtedly more…

Java collection List, Set, Map, Queue, Deque

Java collection List, Set, Map, Queue, Deque

Collections are a very important part of the foundation of Java,Java provides a very rich collection API,Understand the characteristics of each collection,How to use the correct collection in various scenarios “Very important” is also the most basic quality of a Java programmer. Overall understanding The most basic and most commonly used collections in Java are mainly “Set” and “List” ;Map,Queue,Deque. Collection is the top-level interface of the collection List,Set,Queue. Collection inherits from the Iterable interface to implement traversal of elements. The relationship between each class or interface is as shown in the following class diagram: List List is an ordered collection interface, inherited from Collection, has three implementation classes,ArrayList,LinkedList&#xff0c ;Vector, each has its own characteristics. ArrayList,The bottom layer is implemented through arrays,Elements have subscripts,Randomly reading elements through subscripts is highly efficient,The query time complexity is O(1). The disadvantage is that “when inserting or deleting elements”, “need to move elements” or when the array storage space is insufficient, “array expansion” is relatively expensive. In summary, ArrayList is suitable for finding and traversing elements but not for inserting and deleting elements. And ArrayList is thread-unsafe. LinkedList,The bottom layer is implemented through a linked list,Elements have no subscripts,Suitable for dynamic insertion and deletion…

STL basic container: is string, vector, list, deque, set, map_string[] ordered?_cy941228’s blog

class=”markdown_views prism-atom-one-dark”> Basic containers in STL are: string, vector, list, deque, set, map set and map are unordered storage elements, which can only be accessed through the interface it provides set: collection, used to judge whether an element is in a group, less used map: mapping, equivalent to a dictionary, mapping one value to another value, if you want to create a dictionary, use it’s alright string, vector, list, deque, set are ordered containers 1.string string is the implementation of basic_string, and it is stored continuously in memory. In order to improve efficiency, there will be reserved memory, such as string s= “abcd”, then the space used by s may be 255, when string is inserted into s again When adding content, memory will not be allocated again. It will not apply for memory again until the content is > 255, thus improving its performance. When the content is > 255, string will first allocate a new memory, and then copy the content over , and then copy the previous content. The operation on string, if it is added to the end, generally does not need to allocate memory, so the performance is the fastest; If it is an operation…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索