Python → Java Glossary

Quick reference for the most common syntax differences.

Null / None

PythonJavaNotes
NonenullNull value
if not xif (x == null)Null check
x or yx != null ? x : yNull fallback

Data Structures

PythonJavaNotes
dictHashMap<K,V>Key-value map
setHashSet<T>Unique elements
listArrayList<T>Dynamic array
dequeArrayDeque<T>Double-ended queue
[] as stackStack<T>LIFO stack
dequeLinkedList<T>Queue (FIFO)
[0]*nnew int[n]Fixed array
[0]*n (list)Arrays.fill(arr, 0)Initialize

String Operations

PythonJavaNotes
s[::-1]new StringBuilder(s).reverse().toString()Reverse string
s == ts.equals(t)String equality — never use == in Java
for c in sfor (char c : s.toCharArray())Iterate chars
s[i]s.charAt(i)Access char
s[i:j]s.substring(i, j)Slice string
'x' * n"x".repeat(n)Repeat string (Java 11+)
int(c)c - '0'Char to int digit
ord(c)(int) cChar to ASCII
str(n)String.valueOf(n)Int to string
''.join(lst)String.join("", list)Join list

Math & Numbers

PythonJavaNotes
float('inf')Integer.MAX_VALUEPositive infinity / max
float('-inf')Integer.MIN_VALUENegative infinity / min
a // ba / bInteger division (both ints)
a ** bMath.pow(a, b)Power
abs(x)Math.abs(x)Absolute value
max(a, b)Math.max(a, b)Max of two
min(a, b)Math.min(a, b)Min of two
divmod(a, b)a/b, a%bQuotient and remainder

Control Flow

PythonJavaNotes
and&&Logical AND
or||Logical OR
not!Logical NOT
True / Falsetrue / falseBooleans (case sensitive)
elifelse ifElse-if branch
while True: ... breakdo { ... } while (cond)Do-while loop
x if c else yc ? x : yTernary expression
a <= x < ba <= x && x < bChained comparison

Sorting

PythonJavaNotes
lst.sort()Arrays.sort(arr)In-place sort
sorted(lst)Arrays.sort(arr.clone())Returns new sorted
lst.sort(key=fn)Arrays.sort(arr, (a,b) -> ...)Custom sort
lst.sort(reverse=True)Arrays.sort(arr, Collections.reverseOrder())Descending sort

Class Definitions

PythonJavaNotes
def __init__(self)ClassName() { }Constructor
self.x = ythis.x = yInstance variable
def method(self)public void method()Instance method
isinstance(x, T)x instanceof TType check