Member-only story

Python Array vs Java Array

LIU YONGLIANG
5 min readAug 2, 2020

--

I started coding with Python. In Python, the array is dynamic and you do not have to worry about the type of objects that it contains or the length of the array that it starts with. With that understanding of how arrays work, I was quite uncomfortable with strongly typed languages such as C or Java. One of my frustrations was the following:

Suppose I want to loop over a string and take only the uppercase letters. In Python I would simply do:

def func(s):
ans = []
for i in s:
if i == i.upper():
ans.append(i)
return ans

But in C (or Java), how do I initialize an array with a fixed size when I do not know what that final size will be?

After learning about data structures and algorithms, I finally have a slight sense of how things work behind the scene, and in this article, I would try my best to explain it, mainly for reflection purposes.

Why Array?

It all started with the need to group data based on certain criteria. Most of the time we would like to group data of the same type so that we can organize the information better for storage as well as retrieval.

Here comes primitives, the stuff that we get out of the box in programming languages such as Java, and are the building blocks for bigger programs. We have Integer…

--

--

LIU YONGLIANG
LIU YONGLIANG

Written by LIU YONGLIANG

Computer Science Student @ National University of Singapore. Connect with me @ https://www.linkedin.com/in/-yong-/

No responses yet