140. Searching in big files

Searching and counting the number of occurrences of a certain string in a file is a common task. Trying to achieve this as fast as possible is a mandatory requirement, especially if the file is big (for example, 200 GB).

Note that the following implementations assume that string 11 occurs only once in 111, not twice. Moreover, the first three implementations rely on the following helper method from Chapter 1, Strings, Numbers, and Math, the Counting a string in another string section:

private static int countStringInString(String string, String tofind) {
return string.split(Pattern.quote(tofind), -1).length - 1;
}

With that being said, let's take a look at several approaches to this problem.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.18.218