This is an old revision of the document!
Basic data structures in different languages
Having dealt with multiple different programming languages creates some confusion how and in which place the data structures are implemented in each of the languages. This page tries to provide some overview of basic ds.
Concurrency
Java
Python3
- Threading
- Lock
- RLock
- Condition
- Semaphore
- Event
- Queue
Stack
LIFO
Java
Stack<E>
or
Deque<Integer> stack = new ArrayDeque<Integer>();
Operations:
empty, pop, peek, push, search
Python 3
// simple lists letters = [] last_item = letters.pop()
Operations:
append, pop
Queue
FIFO
Java
Collection interface Queue
- Thread-safe: PriorityBlockingQueue
- Not Thread-safe: PriorityQueue, LinkedList
Operations
add() peek() element() throws NoSuchElementException when queue is empty remove() removes and returns the head of the queue poll() size()
Python 3
from collections import deque first_item = numbers.popleft()
Operations:
append, pop, popleft
Math funcs
Java
Math.min, Math.max (int) Math.pow(2, 3)
String funcs
Java
str.indexOf // (first occurence of Character/String; + index to start; Returns -1 if not found, else idx str.charAt // Character str.substring(int beginIndex, int endIndex) // actual start (=0), but end is lenght)