Skip to Content
Java Coding Problems
book

Java Coding Problems

by Anghel Leonard
September 2019
Intermediate to advanced
816 pages
18h 47m
English
Packt Publishing
Content preview from Java Coding Problems

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Coding Problems - Second Edition

Java Coding Problems - Second Edition

Anghel Leonard
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9781789801415Supplemental Content