File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes repeated println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "repeated println" Watch "repeated println" New topic

repeated println

Crescento Anho

Joined: Nov 20, 2007
Posts: 4
I want to check which words that i read from an input text file (one word per line) do not exist in an array of strings (that I already have in my program). I used the .equals to compare the word to every word of my array. Then when I ask the program to print, when a word does not occur in the array I see e.g. 10 times (=number of elements in the array) the phrase ("The word" + fileLine+ "does not occur."). What should I do? When using array there is no 'boolean cointains ();'
[ November 22, 2007: Message edited by: Crescento Anho ]
Katrina Owen

Joined: Nov 03, 2006
Posts: 1367
I guess you could write a method which returns a boolean...
The first thing that comes to mind would be

// create method that takes two parameters: the fileLine, and the array
// set a boolean flag to false
// go through the whole array
// if you encounter the word, set the flag to true
// return the flag

There are probably dozens of good ways to do it (and maybe even something in the API).
It is sorta covered in the JavaRanch Style Guide.
subject: repeated println
It's not a secret anymore!