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 using string.toCharArray()
method and now i am working with charArray[index]
. which takes less time than string.charAt[index]
method. However i want to know that, is there any other way which is faster than string.toCharArray();
method?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With