top of page

Basic collections - JAVA

Welcome in last material before first program!

This topic will be about collections almost the most important things like all. :D I will talk just for a while, I know it will be just a begging and it is totally basics containers not all standard containers.

Containers can be one or more dimensional - simple example:

one dimensional (1x5) [1,2,3,4,5]

two dimensional (3x5)

[1,2,3,4,5]

[6,7,8,9,10]

[11,12,13,14,0]

ArrayList - is the most basic container without many function implemented. It is kind of dynamic table, plus is that you can fast take element from known place, but deleting from the middle can be slow, especially when you have many elements.

Implemented interface: List

List list1 = new ArrayList();

List list2 = new ArrayList(16);

As also functions like add, remove at x, length etc. Everything is in the packet for collection and you don't need to implement it.

LinkedList - Kind of link table, you can add and delete it fast, but get object from known place can take a while, because you have just first element and you need to iterate from one to another to find right place in memory.

Implemented interfaces: List, Deque

List list1 = new LinkedList();

List list2 = new LinkedList(16);

ArrayDeque - One of more interesting thing from this collection is information that it is kind of mixed table and bi-directional queue. You have fast access to first and last element and rest behavior is just like in bi-directional queue.

Implemented interfaces: Deque

PriorityQueue - priority queue means that you have queue, but first element which will be taken is that with the biggest value and last is that with the smallest priority.

Implemented interfaces: Queue

As also functions like push (add), pop (get), length etc. Push and pop are add and remove, but in queues.

HashSet - Fast finding and adding elements, hash function will give you hash from your value. Hash is kind of unique key, but in set you have just value which need to be unique.

Implemented interfaces: Set

HashMap - Hash map is similar to set, but you have key - hash and values. The other things are similar to HashSet.

Implemented interfaces: Map

TreeSet - Red-black tree implementation, of course value - key should be unique.

Implemented interfaces: NavigableSet

TreeMap - Red-black tree implementation, of course key and value. Key should be unique.

Implemented interfaces: NavigableMap

LinkedHashSet - Table of keys with LinkedList implementation ordered.

Implemented interfaces: Set

LinkedHashMap - Table of keys and values with LinkedList implementation ordered.

Implemented interfaces: Map

Of course you can implement more containers using interfaces, but this you can use at the beginning of your programming journey. The most important containers are here, so try to use them in yours applications.

Subscribe me!

Be sure that you read all.

  • Facebook Clean
  • Black Twitter Icon
  • Black Instagram Icon
  • Black YouTube Icon
Recent Posts
bottom of page