0% found this document useful (0 votes)
121 views4 pages

Java LeetCode Cheat Sheet

This document provides a comprehensive overview of essential Java methods and concepts useful for solving LeetCode problems. It covers various data structures such as Strings, Arrays, ArrayLists, HashMaps, HashSets, Stacks, Queues, PriorityQueues, and StringBuilders, along with their key methods. Additionally, it includes Math functions, bit manipulation techniques, and useful algorithmic patterns.

Uploaded by

manish7.2.2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views4 pages

Java LeetCode Cheat Sheet

This document provides a comprehensive overview of essential Java methods and concepts useful for solving LeetCode problems. It covers various data structures such as Strings, Arrays, ArrayLists, HashMaps, HashSets, Stacks, Queues, PriorityQueues, and StringBuilders, along with their key methods. Additionally, it includes Math functions, bit manipulation techniques, and useful algorithmic patterns.

Uploaded by

manish7.2.2004
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

You might also like