"Hi, Amigo. I'd like to give you a couple of tasks about collections:"
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
Set of plants
Create a HashSet with String elements.
Add the following strings to it:
watermelon
banana
cherry
pear
cantaloupe
blackberry
ginseng
strawberry
iris
potato
Display the contents of the collection, each element on a new line.
Watch how the order of the entries has changed.
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
Map of 10 pairs
Create a HashMap, and add 10 string pairs:
watermelon - melon, banana - fruit, cherry - fruit, pear - fruit, cantaloupe - melon, blackberry - fruit, ginseng - root, strawberry - fruit, iris - flower, potato - tuber.
Display the contents of the collection, each element on a new line.
Example output:
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
Values on the screen!
There is a HashMap. 10 different strings have been added to it.
Display a list of values on the screen, each element on a new line.
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
HashMap of Objects
There is a HashMap. 10 different object pairs have been added to it.
Display the contents of the collection, each element on a new line.
Example output: (here we just show one line):
Sim - 5
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
Display a list of keys
There is a HashMap. 10 different strings have been added to it.
Display a list of keys on the screen, each element on a new line.
14
Task
New Java Syntax,
level 14,
lesson 3
Locked
Map of cats
There is a Cat class with a String name.
Create a Map.
Add 10 cats to the collection. The cat's name should be used as the key.
Display the result on the screen, each element on a new line.
GO TO FULL VERSION