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 ArrayList in Java. To save time, we can use ‘diamond notation’, as ArrayList<>(); 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-each loop to loop through a collection such as an ArrayList.
    for (String item : items) {
      // do something with item
    }

An iterator is an object that provides functionality to iterate over all elements of a collection.

0 items under this folder.