From 01e2dcd29916d414e06fd4b580eb61e46f6e4e8c Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 7 Mar 2020 18:37:27 -0600 Subject: [PATCH] list interface --- study/COLLECTIONS.MD | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/study/COLLECTIONS.MD b/study/COLLECTIONS.MD index e534c71..64305f0 100644 --- a/study/COLLECTIONS.MD +++ b/study/COLLECTIONS.MD @@ -36,6 +36,8 @@ This page will be using [javaTpoint](https://www.javatpoint.com/collections-in-j - [Similarities and Differences](#similarities-and-differences) - [ArrayList vs Vector](#arraylist-vs-vector) - [HashSet vs TreeSet vs LinkedHashSet](#hashset-vs-treeset-vs-linkedhashset) + - [Tips and Tricks](#tips-and-tricks) + - [Datatype Conversion](#datatype-conversion) @@ -91,6 +93,20 @@ All methods the Collection interface implements can be seen [here](#methods-of-t ### List Interface +List interface is the child interface of Collection interface. It inhibits a list type data structure in which we can store the ordered collection of objects. Lists can have duplicate values. + +List interface is implemented by the classes [ArrayList](#arraylist-class), [LinkedList](#linkedlist-class), [Vector](#vector-class), and [Stack](#stack-class). + +Remember, that *as a Interface*, `List`s cannot be instantiated, but can be used to type any of the implementing classes. For example: + +```java +List list; +list = new ArrayList(); +list = new LinkedList(); +list = new Stack(); +list = new Vector(); +``` + ### Queue Interface ### Deque Interface @@ -135,4 +151,14 @@ See [ArrayList vs Vector](#arraylist-vs-vector). ### ArrayList vs Vector -### HashSet vs TreeSet vs LinkedHashSet \ No newline at end of file +### HashSet vs TreeSet vs LinkedHashSet + +## Tips and Tricks + +### Datatype Conversion + +To convert from Primitive Arrays to Object-based ArrayLists, Stacks or Queues, use `Arrays.asList(T[])`. + +It returns a *fixed-size* `List` that directly modifies the entries of the original Array, so be careful. + +Most people feed this directly into a new `ArrayList` in order to avoid overwriting data, as well as to take advantage of ArrayList features (dynamically resizing). \ No newline at end of file