charAt() or substring? Which is faster?

后端 未结 6 2376
天命终不由人
天命终不由人 2020-12-15 10:07

I want to go through each character in a String and pass each character of the String as a String to another function.

String s = \"abcdefg\";
for(int i = 0         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 10:51

    I would first obtain the underlying char[] from the source String using String.toCharArray() and then proceed to call newFunction.

    But I do agree with Jesper that it would be best if you could just deal with characters and avoid all the String functions...

提交回复
热议问题