Introduction to Collections
A collection object can store an arbitrary number of other objects. There is no pre-defined limit to number of objects.
- Typically we use
ArrayListin Java. To save time, we can use ‘diamond notation’, asArrayList<>();to avoid typing out the type again. Type is inferred from the variable we are assigning to.
A class library is a library of useful classes. These libraries are referred to as *packages* when working with Java.
A loop can be used to execute a block of statements repeatedly without having to write them multiple times.
- We can use a
for-eachloop to loop through a collection such as anArrayList.for (String item : items) { // do something with item }
An iterator is an object that provides functionality to iterate over all elements of a collection.