r/javahelp • • 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

11 comments sorted by

View all comments

8

u/Philboyd_Studge May 23 '20

Creative use of regex might do the trick, but for pure speed and memory usage, using char arrays would probably be the best.

1

u/[deleted] May 23 '20

Fortunately the lines (and each field) have a fix length, so I don't need to search for them.

I'll give it a try to char array, I think I can make that change easily.

Thanks