Being a Collection
subtype all methods in the Collection
interface are also available in the List
interface.
Since List
is an interface you need to instantiate a concrete implementation of the interface in order to use it. You can choose between the following List
implementations in the Java Collections API:
- java.util.Vector
Vectors(Java 1.1) (Click on link to see tutorial on it)
--uses array to implement list - java.util.ArrayList
ArrayList (Click on link to see tutorial on it)
--uses array to implement List
– not thread-safe, otherwise same as Vector - java.util.LinkedList
LinkedList (Click on link to see tutorial on it)
--List interface implemented as a doubly-linked list
– access to elements is not constant time
– better performance for frequent add/remove operations in middle of List - java.util.Stack
Stack
List
implementations in the java.util.concurrent
package, which we will see later.Here are a few examples of how to create a List
instance:
List listA = new ArrayList();
List listB = new LinkedList();
List listC = new Vector();
List listD = new Stack();
No comments:
Post a Comment