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
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:
- How to upload a file to another server using cURL and PHP?Best solution by Stack Overflow
- How to cancel a file upload using an iframe?Best solution by Stack Overflow
- How to Read xml file in java?Best solution by Stack Overflow
- How to count the number of lines in a file using Bash?Best solution by Stack Overflow
- How to write XML file with Java and read it?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.