Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
48 views1 page

Python vs Java Data Structures Guide

The document compares data structures in Python and Java, highlighting syntax differences for lists, sets, tuples, dictionaries, and arrays. Python lists are dynamic and can store mixed types, while Java uses ArrayLists. Additionally, Python sets are unordered and remove duplicates, and tuples in Python are immutable, unlike Java's lack of native tuples.

Uploaded by

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

Python vs Java Data Structures Guide

The document compares data structures in Python and Java, highlighting syntax differences for lists, sets, tuples, dictionaries, and arrays. Python lists are dynamic and can store mixed types, while Java uses ArrayLists. Additionally, Python sets are unordered and remove duplicates, and tuples in Python are immutable, unlike Java's lack of native tuples.

Uploaded by

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

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.

You might also like