728x90
저번의 queue에 이어 list에 대해서도 알아보자.
(javadoc, 구현 코드를 중심 분석해볼 예정)
- Collection
- List
- AbstactionCollection
- AbstractList
- ArrayList
- AbstractSequentialList
- LinkedList
- Vector
- Stack
- AbstractList
List
sequence라고도 알려진 순서가 있는 collection이다. 각각의 원소가 어디에 있는지 알 수 있다. 정수인 인덱스를 통해, 원소에 접근할 수 있고, 검색할 수 있다.
Set과는 다르게, 일반적으로 중복을 허용한다. null인 원소를 허용한다.
public interface List<E> extends Collection<E>
* An ordered collection (also known as a <i>sequence</i>). The user of this
* interface has precise control over where in the list each element is
* inserted. The user can access elements by their integer index (position in
* the list), and search for elements in the list.<p>
* Unlike sets, lists typically allow duplicate elements. More formally,
* lists typically allow pairs of elements <tt>e1</tt> and <tt>e2</tt>
* such that <tt>e1.equals(e2)</tt>, and they typically allow multiple
* null elements if they allow null elements at all. It is not inconceivable
* that someone might wish to implement a list that prohibits duplicates, by
* throwing runtime exceptions when the user attempts to insert them, but we
* expect this usage to be rare.<p>
AbstractCollection
public abstract class AbstractCollection<E>
extends Object
implements Collection<E>
컬렉션 인터페이스의 뼈대를 제공한다.
https://docs.oracle.com/javase/7/docs/api/java/util/AbstractCollection.html
This class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface.
To implement an unmodifiable collection, the programmer needs only to extend this class and provide implementations for the iterator and size methods. (The iterator returned by the iterator method must implement hasNext and next.)
To implement a modifiable collection, the programmer must additionally override this class's add method (which otherwise throws an UnsupportedOperationException), and the iterator returned by the iterator method must additionally implement its remove method.
The programmer should generally provide a void (no argument) and Collection constructor, as per the recommendation in the Collection interface specification.
The documentation for each non-abstract method in this class describes its implementation in detail. Each of these methods may be overridden if the collection being implemented admits a more efficient implementation.
This class is a member of the Java Collections Framework.
AbstractList
1.2부터 제공
리스트를 구현하는데 필요한 뼈대를 제공한다. random access 하게 데이터를 저장한다.
리퀄션한 LinkedList는 AbstractSequentailList를 사용하는게 더 낫다.
* This class provides a skeletal implementation of the {@link List}
* interface to minimize the effort required to implement this interface
* backed by a "random access" data store (such as an array). For sequential
* access data (such as a linked list), {@link AbstractSequentialList} should
* be used in preference to this class.
ArrayList
1.2부터 제공. List를 구현하여 resizeable한 배열. null인 원소가 들어갈 수 있다.
Vector와 거의 유사하지만 스레드세이프 여부만 다르다.
public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
* Resizable-array implementation of the <tt>List</tt> interface. Implements
* all optional list operations, and permits all elements, including
* <tt>null</tt>. In addition to implementing the <tt>List</tt> interface,
* this class provides methods to manipulate the size of the array that is
* used internally to store the list. (This class is roughly equivalent to
* <tt>Vector</tt>, except that it is unsynchronized.)
AbstractSequentialList
List를 제공하는데 뼈대를 제공함. sequential access 가능하게 데이터를 저장한다.
public abstract class AbstractSequentialList<E> extends AbstractList<E>
* This class provides a skeletal implementation of the <tt>List</tt>
* interface to minimize the effort required to implement this interface
* backed by a "sequential access" data store (such as a linked list). For
* random access data (such as an array), <tt>AbstractList</tt> should be used
* in preference to this class.<p>
* This class is the opposite of the <tt>AbstractList</tt> class in the sense
* that it implements the "random access" methods (<tt>get(int index)</tt>,
* <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
* <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
* the other way around.<p>
LinkedList
1.2부터 제공 null허용.
* Doubly-linked list implementation of the {@code List} and {@code Deque}
* interfaces. Implements all optional list operations, and permits all
* elements (including {@code null}).
*
* <p>All of the operations perform as could be expected for a doubly-linked
* list. Operations that index into the list will traverse the list from
* the beginning or the end, whichever is closer to the specified index.
public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, java.io.Serializable
Vector
1.0부터 제공 스레드 세이프함. 함수들이 synchronzied하게 선언됨.
public class Vector<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
* The {@code Vector} class implements a growable array of
* objects. Like an array, it contains components that can be
* accessed using an integer index. However, the size of a
* {@code Vector} can grow or shrink as needed to accommodate
* adding and removing items after the {@code Vector} has been created.
*
Stack
1.0부터 제공. LIFO
* The <code>Stack</code> class represents a last-in-first-out
* (LIFO) stack of objects. It extends class <tt>Vector</tt> with five
* operations that allow a vector to be treated as a stack. The usual
* <tt>push</tt> and <tt>pop</tt> operations are provided, as well as a
* method to <tt>peek</tt> at the top item on the stack, a method to test
* for whether the stack is <tt>empty</tt>, and a method to <tt>search</tt>
* the stack for an item and discover how far it is from the top.
public
class Stack<E> extends Vector<E>
'개발 > Java' 카테고리의 다른 글
SplitIterator (0) | 2021.05.17 |
---|---|
Primitive Wrapper Class (0) | 2021.05.17 |
java.util.collections 총정리 Queue편 (0) | 2021.05.15 |
Netty란? (0) | 2021.05.14 |
Lombok의 동작원리 (1) | 2021.05.13 |