Java Notes for LeetCode (Essential Methods & Concepts)
1. String Methods
- charAt(i)
- substring(start, end)
- indexOf(char)
- lastIndexOf(char)
- length()
- equals(str)
- equalsIgnoreCase(str)
- toCharArray()
- split(regex)
- replace(old, new)
- startsWith(prefix)
- endsWith(suffix)
- contains(seq)
- trim()
- toLowerCase()
- toUpperCase()
2. Array Methods & Techniques
- [Link](arr)
- [Link](arr, val)
- [Link](arr1, arr2)
- [Link](arr, newLength)
- for-each loop
- 2D Arrays basics
3. ArrayList Methods
- add(value)
- get(index)
- set(index, value)
- remove(index)
- contains(value)
- size()
- clear()
- isEmpty()
- indexOf(value)
4. HashMap Methods
- put(key, value)
- get(key)
- getOrDefault(key, defaultVal)
- containsKey(key)
- containsValue(value)
- remove(key)
- keySet()
- values()
- entrySet()
- size()
- isEmpty()
- clear()
5. HashSet Methods
- add(value)
- contains(value)
- remove(value)
- size()
- isEmpty()
- clear()
- iterator()
6. Stack Methods ([Link])
- push(value)
- pop()
- peek()
- isEmpty()
- search(value)
7. Queue (LinkedList as Queue)
- add(value)
- offer(value)
- poll()
- peek()
- isEmpty()
- size()
8. PriorityQueue (Min/Max Heap)
- add(value)
- offer(value)
- poll()
- peek()
- size()
- isEmpty()
9. StringBuilder Methods
- append(str)
- insert(offset, str)
- delete(start, end)
- reverse()
- toString()
- length()
10. Math Functions
- [Link](a, b)
- [Link](a, b)
- [Link](x)
- [Link](a, b)
- [Link](x)
- [Link](x)
- [Link](x)
- [Link](x)
11. Bit Manipulation (common ops)
- x << n // x multiplied by 2^n
- x >> n // x divided by 2^n
-x&y
-x|y
-x^y
- ~x
12. Useful Patterns
- Two pointers
- Sliding window
- Hashing
- DFS/BFS
- Backtracking
- Prefix Sum
- Binary Search
- Greedy
- Dynamic Programming (DP)