Collections Flashcards
(18 cards)
List
Accepts duplicates, has an index number.
ArrayList
retrieving is faster (Get) holds non-primitive data-types
LinkedList
Add, addAll, remove, removeIf, retainAll.
Vector
A synchronized version of ArrayList
Stack
Syncronized version of arraylist With LIFO (last in first out) organization, pop() = LIFO
Set
doesn’t accept duplicates, does not have an index
HashSet
Random
LinkedHash Set
keeps assertion order
TreeSet
Ascending order doesn’t accept Null.
Queue
Accepts duplicates, No index, FIFO (first in first out)
poll() = FIFO
Iterable
Only for collections. Allows to properly remove objects.
HashMap
Keys are in random order.
LinkedHashMap
Insertion order
TreeMap
Ascending order doesn’t accept Null
HashTable
Keys are in random order, synchronized, does not accept null.
Collections List Key Points
A list is an ordered collection of elements. Some languages call it a sequence or an array of varying lengths.
Collections Set Key Points
A collection that contains no duplicate elements. Like a mathematical Set the interface denotes a collection that holds elements and basically answers a single question: is a given element contained in the set.
Doesn’t specify the order of elements when you iterate them, but all set implementations are created with the performance of the contains method in mind.
Two Implementations would be HashSet and TreeSet
HashSet: hashes the elements and distributes them into buckets by the hash value. Tree Set is backed by a balanced tree, which makes it ordered and navigable.
Typically use-cases for sets do not require navigating from element to element so the HashSet is the goto implementation you’ll tend to use.
Collections Queue Key Points
a Queue is designed to hold elements prior to processing, the elements wait in line to be consumed and can be added to the tail of the queue.
Queues are those fundamental pieces of software that tie components together. IE: when components are communicating in a system, there’s typically a queue of messages sitting between them.
Queues are a special sort of collection as they mainly use the Queue interface, rather than methods inherited from the Collections Interface. IE: .offer / .poll / .peek