Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repeated println

 
Crescento Anho
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic