Jackson Ennis Jackson Ennis -3 years ago 122
Java Question

How to check If a string is a word?

rookie programmer here.

By word I mean like "apple" is a word but "opple" isn't.

So I wanted to make a really simple app that checked to see what the user inputs is a word or not.

Is there a widget or something I can import to do this?

I haven't seen any documentation on this, but I know spellcheck is built into the phone, so I could use some help.

Answer Source

There may be a lot way to do this but one way is you basically need to have a list of word in your root directory of your project. After that you user your code to check String is part of the word list you have it in your root directory or not.

If you are using java , you may do so as follow `

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Dictionary
    private Set<String> wordsSet;

    public Dictionary() throws IOException
        Path path = Paths.get("words.txt");
        byte[] readBytes = Files.readAllBytes(path);
        String wordListContents = new String(readBytes, "UTF-8");
        String[] words = wordListContents.split("\n");
        wordsSet = new HashSet<>();
        Collections.addAll(wordsSet, words);

    public boolean contains(String word)
        return wordsSet.contains(word);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download