Member-only story

From Python To Java (Part 4) — Lists (Python) VS ArrayLists (Java)

Liu Zuo Lin
4 min readDec 19, 2021

--

This series of articles is written for those of you who are somewhat comfortable in Python, and are looking to pick up some Java. In this article, we’ll run through lists in Python and the differences against ArrayLists in Java, which is essentially the equivalent of a Python list.

Creating A List/ArrayList

Python Lists

lis = ["apple", "orange", "pear"]
lis = [4, 5, 6]
lis = [3.14, 2.718, 1.414, 1.732]
lis = ["apple", 4, 3.14, None, True, [], {}]
  • In Python, we can simply type a pair of square brackets, put some stuff inside (this must be valid of course) and we’ve got ourselves a list
  • Python lists can contain multiple data types — we can have integers, floats, strings etc etc all together in one list.

Java ArrayLists

import java.util.ArrayList;
  • The first thing about Java ArrayLists we need to know is that it is the equivalent of a list in Python.
  • The second thing we need to know is that we need to import it using the statement above — put this statement at the top of your Java file before your class definition.
  • The third thing we need to know is that ArrayLists can only…

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

No responses yet