• Post Reply Bookmark Topic Watch Topic
  • New Topic

find all word from text file  RSS feed

 
artem ruzhov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i have a litle problem i have a test task ( string which represents text to search in file, i.e. if it q=java - should return all
strings which equals to ‘java’ or containing it. If q is blank or missing - should return
all text from file) its example i create solution they work but i know its not good idea maybe you help me and say best way my solution :
 
L Foster
Ranch Hand
Posts: 242
14
Android Angular Framework AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does not look bad, per se. Some suggestions: you may not need that whole intermediate "list" list. Instead, maybe you could do the "m.equals()" part within the s.hasNext() loop. It could save a bit of memory. Also, OO folks like to work to the interface when possible. So you could use:



this also eliminates one of the Generics' type declarations that is not needed. Of course if you are not making a list, that won't be in the code anyway. BTW, if you

Depending on how messy your input data is, you may wish to clean it up. Maybe get rid of the punctuation, make everything lower case, etc.

Finally, rather than just the stack trace, if it were me, I would do the check for FileNotFound up front, and make a clear message that this happened. But that may be a matter of taste. With a command-line, you will be expecting a user to type in, in error-prone fashion, some path. Then they will see this complicated stack trace. So, you could make it easier for them. Perhaps you are checking before calling "findKeyWord()", and the trace is just the last line of defense?

BTW, this seems to do what you say, but you will wind up with a lot of repeats of the input string. You could do things like count occurrences, or find offsets. Just a thought.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!