私の問題は、メイン メソッドを実行しても何も出力されないことです。私はHashSet
s にかなり慣れていないので、本当にばかげたことが原因で機能しないのではないかと心配しています。
dic
はもともと an でしたが、効率のために sArrayList
に変換しようとしています。HashSet
private Set<String>dic = new HashSet<String>(100000);
public void dictionary(){//reads/intializes arraylist dic from a file
File data = new File("dictionaryForJava.txt");
Scanner scanner=null;
try {
scanner = new Scanner(data);
while (scanner.hasNextLine()) {
dic.add(scanner.nextLine());
}
} catch (FileNotFoundException fnfe) {}
if(scanner!=null)scanner.close(); // need if if file missing
}
public void print () throws IOException{
Iterator it = dic.iterator();
while(it.hasNext())
{
String value =(String)it.next();
System.out.println(value);
}
}
public static void main (String[] args)throws IOException{
words test = new words();
test.dictionary();
test.print();
}