Competitive coding in Java
From C++ to Java: A Quick-Start Guide
This guide is for competitive programmers who are already comfortable with data structures and algorithms in C++ (or another language) and want to quickly find the Java equivalents.
The goal is not to reteach the concepts, but to map your existing knowledge to Java’s syntax and its powerful standard library.
Core Topics & Equivalents
Here is the breakdown of the topics we will cover. Each section provides the Java alternative to common C++ tools.
- Replacing
cin
/cout
withBufferedReader
andPrintWriter
.
- Replacing
The Collections Framework: Dynamic Arrays
- C++
std::vector
↔ JavaArrayList
.
- C++
The Collections Framework: Hash Maps & Sets
- C++
std::unordered_map
↔ JavaHashMap
. - C++
std::unordered_set
↔ JavaHashSet
.
- C++
The Collections Framework: Heaps
- C++
std::priority_queue
↔ JavaPriorityQueue
.
- C++
The Collections Framework: Balanced Trees
- C++
std::map
↔ JavaTreeMap
. - C++
std::set
↔ JavaTreeSet
.
- C++
- C++
std::queue
↔ JavaQueue<T> q = new LinkedList<>();
- C++
std::stack
↔ JavaDeque<T> s = new ArrayDeque<>();
- C++
std::deque
↔ JavaDeque<T> d = new ArrayDeque<>();
- C++
- Custom sorting with
Arrays.sort()
andCollections.sort()
. - Handling arbitrarily large numbers with
BigInteger
.
- Custom sorting with
Last updated on