11

I just looked up array and arrayList

and found out that an array is fixed length and can't be changed while an arraylist can be changed and is variable in length

my question is:

is array == tuple in python?

and is arraylist == list in python?

and if they aren't what are array and arraylist's python equivalent?

1
  • @Tim I did. I asked to clarify whether I am understanding it right or not. I know what a list and tuple is in python and I'm trying to learn java and they behave similarly. that's why I asked the question to clarify if my understanding of it is right or not Commented Sep 25, 2015 at 1:46

2 Answers 2

20

ArrayList in java and list in python are both dynamic arrays. They both have O(1) average indexing time and O(1) average adding an element to the end time.

Array in java is not tuple in python. While it is true that you cannot add elements to both data structures. Python tuple does not support assignment, that is you cannot reassign individual elements in a tuple, while you can in java Array.

Sign up to request clarification or add additional context in comments.

Comments

0
  • Java's ArrayList is similar to Python's List.
  • Nicer than Array for adding and removing items.
  • Java's Array has fixed length like you mentioned.
  • Not sure what its equivalent in Python would be.

2 Comments

so an array is immutable?
Java arrays are not immutable, merely fixed length. There is no direct equivalent in Python; Python types with fixed lengths are usually immutable (because there is no significant benefit to making mutable types have fixed length).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.