Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

An object array is a fixed-size sequence of objects:

The subscript used in constructing object arrays is evaluated as an integer:

We can specify the initial collection of contained objects when we construct the array. Those objects can be any other entity in Groovy, eg, numbers, boolean values, characters, strings, regexes, lists, maps, closures, expandos, classes, class instances, or even other object arrays:

We can make a shallow copy using clone():

We have a special syntax for constructing multi-dimensional object arrays with null initial values:

There are strict rules concerning evaluation when subscripting object arrays:

Implementing an ArrayList with an Object Array

ArrayLists are implemented with object arrays internally. Each ArrayList instance has a capacity, the size of a fixed-size array used to store the elements. This array is always at least as large as the list size, and its capacity grows automatically as elements are added to the list. To see the internal capacity of lists constructed with various values:

For efficiency, we can increase the capacity of a list before adding a large number of elements:

We can see how many times a list has been modified:

  • No labels