Arrays

Suppose we want to store 100 values entered by the user. Knowing what we do so far, we would have to declare 100 different variables to hold the information. This would be doable, but it would be a giant pain.

Next, suppose we want to store a bunch of values entered by the user, but we don’t know how many – it might be 10, it might be 100,000. We could try to declare 100,000 variables, just in case, but even this wouldn’t work if the user decided to store more than that. To solve this problem, we need a convenient to store a list of values. Furthermore, we want this list to be able to hold any number of values, depending on the user’s needs.

Java has a feature called an array that is used to store a variable number of elements.