Collections are used to hold objects. An array is the most basic type of collection.
When we're using an array of a primitive type, we can use a shortcut to initialize our data, as demonstrated here.
We're also not limited to primitive types when using arrays. Here's an example that uses an array of structs.
Review Questions
The following are examples of questions similar to what you can expect to see on the next exam.
- How would you access the first element of an array called "numbers?" numbers[0]
- Can arrays hold multiple data-types? No. You must define the type when you declare the array.
- What is the syntax for initializing an array called "numbers" with these values: 45.2, 55, 101.5? double numbers[] = {45.2, 55, 101.5};