Java CharAt() and deleteCharAt() performance

前端 未结 5 1586
醉酒成梦
醉酒成梦 2020-12-24 07:26

I\'ve been wondering about the implementation of charAt function for String/StringBuilder/StringBuffer in java what is the complexity of that ? also what about the deleteCha

5条回答
  •  盖世英雄少女心
    2020-12-24 07:39

    Since we all know that the string is implemented in JDK as a character array, which implements the randomAccess interface. Therefore the time complexity of charAt should be int O(1). As other arrays, the delete operation has the O(n) time complexity.

提交回复
热议问题