Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Occurence of given string in a large text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Occurence of given string in a large text file" Watch "Occurence of given string in a large text file" New topic
Author

Occurence of given string in a large text file

Hs Raveendran
Greenhorn

Joined: Feb 05, 2010
Posts: 23

Which is the efficient algorithm to find the occurrence of a given string in a given large text file.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Hs Raveendran wrote:Which is the efficient algorithm to find the occurrence of a given string in a given large text file.


There are two prime algorithms for doing this - the Knuth-Morris-Pratt algorithm and the Boyer-Moore algorithm. Both are fairly easy to implement and Google will provide the details. In this case I would probably use the Knuth-Morris-Pratt algorithm since it requires no backtracking.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Occurence of given string in a large text file
 
Similar Threads
can we typecast String to String array
How to send bulk data using Javamail API
Remove bad characters from strings
How to quickly do "File into String, and String into File" ?
searching a large list of words