Java string - compare charAt() and index operator [] -
i wonder whether slower use .charat() convert string variable s char[] a array , access via a[i] instead of s.charat(i) ?
let's working on problem has lots of operator on each character within string.
the implementation of string#charat(int index) oracle's java 7:
public char charat(int index) { if ((index < 0) || (index >= value.length)) { throw new stringindexoutofboundsexception(index); } return value[index]; } it's little safer check, it's exact same behavior.
it slower return char[]
public char[] tochararray() { // cannot use arrays.copyof because of class initialization order issues char result[] = new char[value.length]; system.arraycopy(value, 0, result, 0, value.length); return result; } since have copy first.
Comments
Post a Comment