1

Essentially I need to create a program to filter out the specific characters I input using a scanner from a dictionary file. Example, if I enter 'Stop' the result would be tops spot pots

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
import java.util.stream.Stream;


public class Anagram1 {

    public static void main(String[] args) throws IOException {
    new Anagram1().doIt();
    }

    private void doIt() throws IOException {
        Scanner scanner = new Scanner(System.in);
        while (true) {
           String theWord = scanner.next();
            if (theWord.equals("999")) {
            scanner.close();
            break;
        }
        
        
            ISinglyLinkedList<String> anagrams = listAnagrams(theWord);
            anagrams.forEach(System.out::print);
        }
    }
 
    private ISinglyLinkedList<String> listAnagrams(final String theWord) throws 
     IOException {
        Stream<String> dict = Files.lines(Paths.get("Data", "pocket.dic"));
        ISinglyLinkedList<String> theList = dict
                .collect(Util.toSinglyLinkedList())
            //Add a filter and a forEach to print the specific words you wanna print
        
        
        ;
        dict.close();
        return theList;
    }

}

So far the program only gives me enter code here every single word in the dictionary. Is there a way to filter out only the words that share the same letter?

0 Answers0