'Cannot find symbol - method iterator()
I'm unsure of why I am getting an error for 'cannot find symbol - method iterator' in my public void print() method. I have imported the relevant package and it still wont work, thank you in advance for any help :)
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class Thesaurus
{
private HashMap<String, HashSet<String>> synonyms;
public Thesaurus()
{
HashMap<String, String> synonyms = new HashMap<String, String>();
}
public String populate()
{
HashSet<String> synonyms = new HashSet<String>();
synonyms.add("happy");
synonyms.add("joyful");
synonyms.add("contented");
synonyms.add("cheerful");
synonyms = new HashSet<>();
synonyms.add("angry");
synonyms.add("annoyed");
synonyms.add("vexed");
}
public void print()
{
Iterator<String> s = synonyms.iterator();
while(s.hasNext()){
System.out.println (s.next());
}
}}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
