"Hi, Amigo. I'd like to give you a couple of tasks about collections:"
HashSet of plants
It's time to gather in the harvest. Let's create a HashSet with String elements. And here are the ten strings that we'll add to it: watermelon, banana, cherry, pear, cantaloupe, blackberry, ginseng, strawberry, iris, potato. Then we'll display the contents of the collection, and observe the order of the collection entries.
HashMap of 10 pairs
In the lessons, your mentors explained that a Map is a set of key-value pairs, where the key is a unique name that can be used to access a value. We're going to start working with the HashMap collection. Let's create an instance of this type of collection and tell people about plants. For example: value — fruit, key — watermelon.
HashMap of cats
Here we've decided to make a collection of cats, so we're going to prepare a proper CATalog. In this program, someone has already gone to the trouble of writing a Cat class with a name field. Our task is to create a HashMap and add 10 cats to it. That's enough to start. As you probably already guessed, the cat's name should be used as the key.
Display a list of keys
Hideouts, passwords, keys! The captured secret agent will have to disclose it all without holding anything back… Actually, no. The keys and passwords will be enough. Her captors managed to recover a small program with a HashMap containing ten strings. Your task is to display a list of keys, printing each element on a new line.
Values on the screen!
A secret agent has been ambushed. To prevent the information she was carrying from vanishing, she needs to launch an application on her laptop. In this application, she found and created a HashMap containing 10 strings. Help the secret agent display the values on the screen, printing each element on a new line.
HashMap of Objects
Working with collections requires skill and professionalism. This is the same reason we don't let total noobies shoot a gun. But here on the eighth level, it's time to start digging into them. Suppose we have a HashMap, and 10 different object pairs have been added. Your task is to display the contents of the collection.