本文介绍了Java CharAt()和deleteCharAt()性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道java
中String / StringBuilder / StringBuffer的charAt函数的实现是什么?它的复杂性是什么?
还有什么关于StringBuffer / StringBuilder中的deleteCharAt()?

I've been wondering about the implementation of charAt function for String/StringBuilder/StringBuffer in javawhat is the coomplexity of that ?also what about the deleteCharAt() in StringBuffer/StringBuilder ?

推荐答案

对于 String StringBuffer StringBuilder charAt()是一个固定时间操作。

For String, StringBuffer, and StringBuilder, charAt() is a constant-time operation.

对于 StringBuffer StringBuilder deleteCharAt()是线性时间操作。

For StringBuffer and StringBuilder, deleteCharAt() is a linear-time operation.

StringBuffer StringBuilder 具有非常相似的性能特征。主要区别在于前者是 synchronized (因此是线程安全的),而后者则不是。

StringBuffer and StringBuilder have very similar performance characteristics. The primary difference is that the former is synchronized (so is thread-safe) while the latter is not.

这篇关于Java CharAt()和deleteCharAt()性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 02:37