Reading one character at a time from a large string
13,858
I do not think there is a faster way. But please correct me!
A String instance is backed by a char array. charAt() does some index checks which may be the cause for it being slower than working with the array returned by toCharArray(). toCharArray() simply does a System.arraycopy() of the backing array.
Author by
ravi
Updated on August 09, 2022Comments
-
ravi over 1 year
I have a big string having at most 100000 character. Instead of using
string.charAt[index]
to read a character from the string, I converted that string into char array usingstring.toCharArray()
method and now i am working withcharArray[index]
. which takes less time thanstring.charAt[index]
method. However i want to know that, is there any other way which is faster thanstring.toCharArray();
method?