Lists
Quote
“Should array indices start at 0 or 1? My compromise of 0.5 was
rejected without, I thought, proper consideration.”
— Stan Kelly-Bootle
Lists are a collection of elements that can be accessed by their index.
var empty = Collections.emptyList()
var singleton = Collections.singletonList(1)
var list = [1, 2, 3]
var unmodifiableList = Collections.unmodifiableList(arrayList)
List<Integer> empty = Collections.emptyList();
List<Integer> singleton = Collections.singletonList(1);
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3));
List<Integer> unmodifiableList = Collections.unmodifiableList(arrayList);
const list = [1, 2, 3];
const unmodifiableList = Object.freeze(list);
val empty = emptyList<Int>()
val singleton = listOf(1)
val list = mutableListOf(1, 2, 3)
val unmodifiableList = listOf(1, 2, 3)
l = [1, 2, 3]
unmodifiable_list = tuple(l)
const list: number[] = [1, 2, 3];
const unmodifiableList: readonly number[] = Object.freeze(list);
block-beta
columns 2
block:indices
columns 1
i1("0") i2("1") i3("2") i4("3")
end
block:nums
columns 1
v1["3"] v2["6"] v3["5"] v4["8"]
end
i1 --> v1
i2 --> v2
i3 --> v3
i4 --> v4
style indices fill:transparent
Which one to use?
- ArrayList is the fastest to iterate.
- Use LinkedList when elements are frequently modified.