Read one character at a time from a large string

I have a large string with no more than 100,000 characters. Instead of using string.charAt[index] to read a character from a string, I converted this string to a char array using the string.toCharArray() method, and now I'm working with charArray[index] . which takes less time than string.charAt[index] . However, I want to know if there is another way that is faster than the string.toCharArray(); method string.toCharArray(); ?

+6
source share
1 answer

I do not think there is a faster way. But please correct me!

The String instance is supported by the char array. charAt () performs some index checks, which may be the reason for its slowness, than working with the array returned by toCharArray (). toCharArray () just makes the System.arraycopy () an array of support.

+1
source

Source: https://habr.com/ru/post/911562/


All Articles