r/javahelp • u/[deleted] • May 23 '20
Recommendations on String manipulation
A company I work with is replacing an old COBOL process with Java.
Pretty much the business rules are about reading some long lines from a text file, do some snippin and reordering before writing to a new file text.
That part is covered, but I'm doing some heavy use of String.substring. I haven't seen a real input file, but they are supposed to hold near 2 million lines each.
Because of that, I would like to make the new process as memory efficient as possible. (When I first learned Java they always warned us about the perils of String)
The process will run on a server (don't know the exact specs) if that's useful.
Thanks in advance.
17
Upvotes
3
u/xyphanite Quantum Brewer May 23 '20
You can likely make some estimates about run-time and memory usage based on what you're working with.
This tutorial https://www.baeldung.com/java-read-lines-large-file has some good methods, as you may get a memory exception if you read in the entire file at once or try to write. You may have to get creative when parsing it if you need to re-order content based on previous searches. I think that statements stands true for writing as well. Hope this helps.