HashSet of plants

  • 2
  • Locked
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.
You can't complete this task, because you're not signed in.
Comments (10)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Andrei
Level 39
2 November 2020, 10:57
When displaying the list, why is it printed in a different order than the order I have introduced the strings in the HashSet? On what criteria are the inputs reordered inside the HashSet?
Ibrahim
Level 9 , Minneapolis, United States
30 August 2020, 21:12
if you want to use Iterator, don't forget to import it either explicitly or by wildcard import statement to the whole utility package
Kelly
Level 14 , Omaha, United States
19 March 2020, 00:38
It is very frustrating when the examples in the previous lessons do not work in the practice. According to the last lesson, Set<String> should work to initialize a new HashSet, but it didn't. Also, Iterator didn't work. I found there's a separate import for it, but it's frustrating that some of these things aren't better explained.
Nickolas Johnson
Level 8 , St. Louis, United States of America
4 April 2020, 16:22
You don't necessarily need an iterator for this one. The for each shorthand would work.
for (String text : set) ...
I do agree with you on the Set<String> thing though. I have it as that in my notes from the last section :-/
Roman Grygorczuk
Level 19 , Cracow, Poland
21 September 2020, 06:25
I would recommend to use IntelliJ for this purpose and you will not have any issues with import
Param M
Level 8 , Mumbai, India
11 July 2019, 10:59
why for me the iterator is not working
Roman
Level 41
12 July 2019, 06:43
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
KIN SOCHEAT
Level 34 , Phnom Penh, Cambogia
3 June 2019, 22:48
Thanks
Jyothi
Level 20 , United States
11 December 2018, 14:12
Verify failing declare/initialize HashSet why?
Roman
Level 41
12 December 2018, 06:40
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.