在 Python 中,我可以做一些简单的事情,例如:
# declare lists
A =["a","bnbnb"]
B = [1,2,3]
C = ['x'] + A # (Simple Append)
# iterate over both lists
for x in [A,B,C]: # (Create list of lists on the fly for for loops)
do something to X[0]
等等。
我是 Java 新手 - 并且了解数组是固定大小的,但列表和数组列表不是。我将如何模仿上述内容?
这是我失败的尝试
# declare lists
String[] A ={"a","bnbnb"}
String[] B = [1,2,3]
Stuck here C = ['x'] + A (Simple Append)
# iterate over both lists
for x in [A,B,C]: (Cant seem to do this either)
# do something to X[0]
使用ArrayList
s 只会让它变得更加麻烦 - 我打赌我错过了一些明显的东西。