2017-02-07 9 views
-1

私がしようとしているのは、英語の単語が500,000語含まれているテキストファイルから読み込み、それをパフォーマンス目的のためにHashSetに格納することです。そして、次に、5文字の単語や6文字の単語など、修飾された要素を含むHashSetを返したいと思います。HashSetを反復処理し、修飾された要素でセットを返す方法は?

これは私のコードです。 私はあなたのソリューションに感謝します!

private static HashSet<String> readPuzzleFile(int wordLength) { 
     HashSet<String> unProcessedPuzzle = new HashSet<String>(); 
     try (Scanner file = new Scanner(new File(PATHTOPUZZLE))) { 
      while (file.hasNextLine()) { 
       unProcessedPuzzle.add(file.nextLine()); 
      } 
     } catch (FileNotFoundException e) { 
      System.out.println("No Puzzle File Found!"); 
      return null; 
     } 
     HashSet<String> puzzle = new HashSet<String>(); 
     Iterator iterator = unProcessedPuzzle.iterator(); 
     for (String word : unProcessedPuzzle){ 
      puzzle.addAll(word); 
     } 
     } 
+1

そして、あなたの問題や、あなたの質問は何ですか? – IQV

+0

@IQVちょうどそれを行う方法、申し訳ありません最初の質問にそれを入れて忘れてしまった。 –

+0

何をするには? – shmosel

答えて

-1
private static HashSet<String> readPuzzleFile(int wordLength) { 
     HashSet<String> unProcessedPuzzle = new HashSet<String>(); 
     try (Scanner file = new Scanner(new File(PATHTOPUZZLE))) { 
      while (file.hasNextLine()) { 
       unProcessedPuzzle.add(file.nextLine()); 
      } 
     } catch (FileNotFoundException e) { 
      System.out.println("No Puzzle File Found!"); 
      return null; 
     } 
     HashSet<String> puzzle = new HashSet<String>(); 
     Iterator iterator = unProcessedPuzzle.iterator(); 
     for (String word : unProcessedPuzzle){ 
      puzzle.add(word); //........addAll -> add......... 
     } 
     return puzzle;//........return puzzle......... 
     } 
+0

これは正しい方法ではありませんが、あなたは私に影響を与えました。今私はそれを解決しました、ありがとう! –

関連する問題