October 2017
Beginner
318 pages
7h 26m
English
Once we set up our Map, it's time for us to go through and fill it with information. For this, I think a for loop will be appropriate:
for(int i = 0; i < lastNames.length; i++)
{
famousPeople.put(lastNames[i], firstNames[i]);
}
We're going to need to add a number of pairs of information to our Map, that is, one key and one value, equal to the number of items in either of these arrays. This is because they both have the same length. So let's set up a for loop that iterates through every index from i to the length of (lastNames-1). The i values will map to the indexes of the lastNames array, and because the firstNames array has the same length as the lastNames array, they will map to the indexes of the firstNames ...
Read now
Unlock full access