Krivalar Tutorials 
Krivalar Tutorials

Java Data Structures and Collections


<<Previous

Next >>





Java collections

Java provides a complete library of data structures called Java collections. Collection interface is at the top of the collection hierarchy. List, Set and Queue interfaces extend the collection interface. Map interface is the root from which a variety of Map classes extend. Popular ones are Property, HashMap, Hashtable and WeakHashMap.

List

List is a collection of elements in which there can be duplicates.
Example: ArrayList, LinkedList, Stack, Vector are some of the variants of List in Java

Set

Set is a collection of elements in which does not contain duplicates
Example: HashSet, TreeSet, LinkedHashSet





Queue

Queue is a collection of elements for temporarilty holding of elements before processing.
Single Ended Queue - Elements are added in one end and removed from the other end. Elements can be removed on a First-In-First Out (FIFO) basis.
    Example: PriorityQueue, SynchronousQueue.
Double Ended Queue (Deque) - It is a type of Queue in which elements are added or removed from any end.
    Example: ArrayDeque

List

ArrayList

Unsyncronized version of List data structure based on an array. This is used when you have one thread accessing the list instance. Since it does not maintain any lock, it is relatively faster when not using mutiple threads.

Vector

Synchronized version of List data structure based on an array. This is used when you have multiple threads accessing the same List. One thread adding, reading, updating or removing element from the list is not affected by another thread doing any of these operations.

Stack

Stack is a variant of list. Stack is a collection of elements in which elements can be added and removed from one end on Last In First Out(LIFO) basis

Linked List

Non synchronized version of a Doubly Linked List. Linked list is a data structure in which each element has reference to the next element in the list. Doubly Linked list is a data structure in which each element has two references: one to the next element and another to the previous element in the list.



<<Previous

Next >>





















Searching using Binary Search Tree