ASCII character/string processing and performance - char[] versus String?
801904Apr 29 2013 — edited May 1 2013Hello everyone
I am relative novice to Java, I have procedural C programming background.
I am reading many very large (many GB) comma/double-quote separated ASCII CSV text files and performing various kinds of pre-processing on them, prior to loading into the database.
I am using Java7 (the latest) and using NIO.2.
The IO performance is fine.
My question is regarding performance of using char[i] arrays versus Strings and StringBuilder classes using charAt() methods.
I read a file, one line/record at a time and then I process it. The regex is not an option (too slow and can not handle all cases I need to cover).
I noticed that accessing a single character of a given String (or StringBuilder too) class using String.charAt(i) methods is several times (5 times+?) slower than referring to a char of an array with index.
My question: is this correct observation re charAt() versus char[i] performance difference or am I doing something wrong in case of a String class?
What is the best way (performance) to process character strings inside Java if I need to process them one character at a time ?
Is there another approach that I should consider?
Many thanks in advance