Java APIs Flashcards

1
Q

String

A
  • "..."
  • new String(char[])
  • .charAt(int index)
  • .length()
  • .split(String regex)
  • .toCharArray()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

StringBuilder

A
  • .append(char c)
  • .append(char[] str)
  • .append(String str)
  • charAt(int index)
  • deleteCharAt(int index)
  • insert(int offset, char/char[]/String)
  • .length()
  • .toString()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

java.util.Arrays

A
  • .equals(T[] arr1, T[] arr2)
  • .fill(T[] arr, T value)
  • .sort(T[] arr)
  • .asList(E e, ...)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Array

A
  • {value, value, value, ...}
  • new T[](int size)
  • arr[int index]
  • .length
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Collection to int[]

A

.stream().mapToInt(Integer::intValue).toArray()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Map

A
  • Map<K, V> x = new HashMap<>();
  • new HashMap<>(int capacity)
  • .containsKey(K key)
  • .get(K key)
  • .getOrDefault(K key, V defaultValue)
  • .put(K key, V value)
  • .remove(K key)
  • .size()
  • .isEmpty()
  • .entrySet() -> Set<Map.Entry<K,V>>
  • .keySet() -> Set<K>
  • .values() -> Collection<V>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Set

A
  • Set<E> x = new HashSet<>()
  • .add(E e)
  • .contains(E e)
  • .isEmpty()
  • .remove(E e)
  • .size()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List

A
  • .add(E e)
  • .contains(E e)
  • .get(int index)
  • .isEmpty()
  • .remove(int index)
  • .size()
  • .toArray()
  • Collections.sort(List<T> list)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Queue

A
  • Queue<E> queue = new LinkedList<>()
  • .offer(E e)
  • .poll()
  • .peek()
  • .isEmpty()
  • .size()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Stack

A
  • Stack<E> stack = new Stack<>()
  • .push(E e)
  • .pop()
  • .peek()
  • .size()
  • .empty()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Monotonic

A

Stack or queue that is increasing or decreasing in value

If the next item would break the sorting of the collection, remove elements until the next item can be added

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Formats for Graph Input

A
  • Array of edges [x,y] - [[3,4][2,5][2,4][4,3]]
  • Adjacency list (outgoing edges from i) - [[1], [2], [0,3]]
  • Adjacency matrix (1 means connection) - [[1, 0, 1], [1, 1, 1], [0, 0, 1]]
  • Matrix (like a map)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Heap

A
  • PriorityQueue<T> q = new PriorityQueue<>();</T>
  • min heap by default
  • .add(T)
  • .peek()
  • .remove()
  • .size()
  • maxHeap = new PriorityQueue<>(Comparator.reverseOrder());
How well did you know this?
1
Not at all
2
3
4
5
Perfectly