Java Array ArrayList python 等价物

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32773464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:03:29  来源:igfitidea点击:

Array ArrayList python equivalent

javapythonarraysarraylist

提问by Zion

I just looked up arrayand arrayList

我只是了一下arrayarrayList

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

并且发现了一个阵列是固定的长度,并且不能被改变,而一个数组列表是可以改变的,并且在长度上是可变

my question is:

我的问题是:

is array== tuplein python?

阵列==元组在python?

and is arraylist== listin python?

并且是python中的arraylist== list

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

如果它们不是 array 和 arraylist 的 python 等价物?

采纳答案by Akavall

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

ArrayList在java和listpython中都是动态数组。它们都有 O(1) 平均索引时间和 O(1) 平均添加一个元素到结束时间。

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

Array在java中不是tuple在python中。虽然您不能将元素添加到这两种数据结构中,但这是事实。Pythontuple不支持赋值,即您不能在 a 中重新分配单个元素tuple,而在 java 中可以Array

回答by David

  • 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.
  • Java 的 ArrayList 类似于 Python 的 List。
  • 在添加和删除项目方面比 Array 更好。
  • 就像你提到的,Java 的 Array 有固定长度。
  • 不确定它在 Python 中的等价物是什么。