Data
Python Syntax Java Syntax Notes
Structure
List<Integer> list = new Python lists are dynamic and
List my_list = [1, 2, 3]
ArrayList<>(); can store mixed types.
List<Integer> list = new
Empty List my_list = []
ArrayList<>();
Set<Integer> set = new Python sets are unordered and
Set my_set = {1, 2, 3}
HashSet<>(); remove duplicates.
Set<Integer> set = new {} creates a dict in Python, not a
Empty Set my_set = set()
HashSet<>(); set.
List<Integer> tuple = Python tuples are immutable.
Tuple my_tuple = (1, 2, 3)
[Link](1, 2, 3); Java doesn't have native tuples.
Can simulate using a list or
Empty Tuple my_tuple = () Not directly supported
custom class in Java.
Dictionary / Map<String, Integer> map = Python uses curly braces; Java
my_dict = {"a": 1, "b": 2}
Map new HashMap<>(); uses HashMap, TreeMap, etc.
Empty Map<String, Integer> map =
my_dict = {}
Dictionary new HashMap<>();
import arrayarr = Python array requires the array
Array (typed) int[] arr = new int[]{1, 2, 3};
[Link]('i', [1, 2, 3]) module and type code like 'i'.
Array arr = [1, 2, 3] (list Python lists are often used in
int[] arr = new int[3];
(general) behaves like array) place of arrays.