hey people I need some advice.
my program did not meet the third condition in this task.
could you help me to solve it?
thank you!
package com.codegym.task.task08.task0801;
/*
HashSet of set
Create a HashSet with String elements.
Add 10 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.
Requirements:
1. Declare a HashSet variable with String elements and immediately initialize it.
2. The program should not read strings from the keyboard.
3. The program should add 10 strings to the collection in accordance with the conditions.
4. The program should display 10 strings from the collection, each on a new line.
*/
import java.util.HashSet;
import java.util.Iterator;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
HashSet<String> set = new HashSet<String> ();
set.add ( "watermelon" );
set.add ("banana" );
set.add ("cherry ");
set.add ("pear" );
set.add ("cantaloupe" );
set.add ("blackberry" );
set.add ("ginseng" );
set.add ("strawberry" );
set.add ("iris" );
set.add ("potato" );
Iterator<String> iterator = set.iterator ();
for (String plant : set){
System.out.println (plant );
}
}
}