How to search for a particular string in a text file using java?

How to search a file using Java?

  • I am in an introduction to Computer Science class and have to write a program that checks the spelling of words in a text file. I understand how to read each line of the file or to read each line of the dictionary (a text file located in my usr directory) I just don't know what the method should look like that checks to see if the word exists in the dictionary or not looks like. It obviously needs to return a boolean but I don't know how to do it. Can somebody help me! PLEASE!

  • Answer:

    Your question is very important for which I think you should go online and check this out: http://hitechbooks.com/articles enjoy :)

Donna S at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Well, if you just need to check for equality against a known set, a simple example could look like the following: ArrayList<String> dictionary = new ArrayList<String>(); dictionary.add("something"); // make sure it's entered with a consistent case String word = "Somfthing"; System.out.format("Is the word '%s' in the dictionary (assumedly misspelled)? %s%n", word, dictionary.contains(word.toLowerCase()) ? "yes" : "no"); However, it's important to note that an with large sets of data in the dictionary, a List probably wouldn't be the most efficient lookup -- you'd probably look for something indexed and able to do some inference around common misspellings (character proximity, vowel similarity, etc.).

Cameron O

You should probably ignore case by using equalsIgnoreCase(String obj); this method is in the String class. This is from the documentation: boolean equalsIgnoreCase(String anotherString) Compares this String to another String, ignoring case considerations.

modulo_function

use the equals method in the string class to check for equality. wordToCheck.equals(dictionaryWord) where wordToCheck and dictionaryWord are both String objects

david m

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.