当前位置: 首页 > news >正文

域名备案好了后怎么做网站百度网络营销中心app

域名备案好了后怎么做网站,百度网络营销中心app,校园网站建设网站,绥化网站开发公司要深入了解 StringBuffer 和 StringBuilder 的区别,从底层源码的角度来解析,包括它们的创建、扩容机制等,可以参考 JDK 1.8 的源码。 1. AbstractStringBuilder 类 StringBuffer 和 StringBuilder 都继承自 AbstractStringBuilder。…

        要深入了解 StringBuffer 和 StringBuilder 的区别,从底层源码的角度来解析,包括它们的创建、扩容机制等,可以参考 JDK 1.8 的源码。

1. AbstractStringBuilder 类
        

        StringBuffer 和 StringBuilder 都继承自 AbstractStringBuilder。这个类包含了字符串操作的核心逻辑。

AbstractStringBuilder 源码

abstract class AbstractStringBuilder implements Appendable, CharSequence {char[] value;int count;AbstractStringBuilder(int capacity) {value = new char[capacity];}AbstractStringBuilder() {}public int length() {return count;}public int capacity() {return value.length;}public void ensureCapacity(int minimumCapacity) {if (minimumCapacity > value.length) {expandCapacity(minimumCapacity);}}void expandCapacity(int minimumCapacity) {int newCapacity = value.length * 2 + 2;if (newCapacity < minimumCapacity) {newCapacity = minimumCapacity;}value = Arrays.copyOf(value, newCapacity);}public AbstractStringBuilder append(String str) {if (str == null)str = "null";int len = str.length();ensureCapacity(count + len);str.getChars(0, len, value, count);count += len;return this;}// ... 其他方法 ...
}

2. StringBuilder 类

StringBuilder 继承了 AbstractStringBuilder,并且不做任何同步处理。

StringBuilder 源码

public final class StringBuilder extends AbstractStringBuilder implements java.io.Serializable, CharSequence {public StringBuilder() {super(16);}public StringBuilder(int capacity) {super(capacity);}public StringBuilder(String str) {super(str.length() + 16);append(str);}// 所有的方法都继承自 AbstractStringBuilder,不进行同步
}

3. StringBuffer 类

StringBuffer 继承了 AbstractStringBuilder,并且对所有方法都进行同步处理,以确保线程安全。

StringBuffer 源码

public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence {public StringBuffer() {super(16);}public StringBuffer(int capacity) {super(capacity);}public StringBuffer(String str) {super(str.length() + 16);append(str);}@Overridepublic synchronized StringBuffer append(String str) {super.append(str);return this;}// 所有的方法都进行同步处理
}

4. 扩容机制

扩容机制在 AbstractStringBuilder 中实现。它的核心方法是 expandCapacity,具体如下:

expandCapacity 方法

void expandCapacity(int minimumCapacity) {int newCapacity = value.length * 2 + 2;if (newCapacity < minimumCapacity) {newCapacity = minimumCapacity;}value = Arrays.copyOf(value, newCapacity);
}

初始容量:newCapacity = value.length * 2 + 2,每次扩容时容量会变成原来的两倍加2。
如果新容量小于所需的最小容量,则将新容量设置为最小容量。
通过 Arrays.copyOf 方法将原数组复制到新数组中,并将 value 指向新数组。

5. 创建过程

StringBuilder 创建

StringBuilder sb = new StringBuilder();

调用无参构造函数,初始容量为16。
super(16) 调用 AbstractStringBuilder 的构造函数,value 数组长度为16。

StringBuffer 创建

StringBuffer sb = new StringBuffer();

调用无参构造函数,初始容量为16。
super(16) 调用 AbstractStringBuilder 的构造函数,value 数组长度为16。

6. 扩容示例

假设我们创建一个 StringBuilder,初始容量为16,并向其中添加超过16个字符: 

StringBuilder sb = new StringBuilder();
sb.append("12345678901234567"); // 17个字符

ensureCapacity 方法会检查是否需要扩容。
当前容量是16,不足以容纳17个字符,因此调用 expandCapacity。
计算新容量:newCapacity = 16 * 2 + 2 = 34。
新数组长度为34,原数组内容复制到新数组中。

总结:

        StringBuilder 和 StringBuffer 都继承自 AbstractStringBuilder,并共享其核心实现,包括初始容量和扩容机制。
        线程安全性:StringBuilder 不进行同步处理,而 StringBuffer 对所有方法都进行同步处理。
        扩容机制:扩容策略是原数组长度的两倍加2,当容量不足时扩容,并通过 Arrays.copyOf 方法复制原数组内容。


文章转载自:
http://stipes.Ljqd.cn
http://verbenaceous.Ljqd.cn
http://heavyish.Ljqd.cn
http://flotilla.Ljqd.cn
http://milesian.Ljqd.cn
http://straitness.Ljqd.cn
http://scribe.Ljqd.cn
http://illy.Ljqd.cn
http://unlighted.Ljqd.cn
http://fivepenny.Ljqd.cn
http://solenodon.Ljqd.cn
http://b2b.Ljqd.cn
http://sporular.Ljqd.cn
http://malposition.Ljqd.cn
http://lawrenciana.Ljqd.cn
http://roti.Ljqd.cn
http://spelk.Ljqd.cn
http://hystricomorphic.Ljqd.cn
http://cannibalise.Ljqd.cn
http://anil.Ljqd.cn
http://matchwood.Ljqd.cn
http://fundholder.Ljqd.cn
http://lipositol.Ljqd.cn
http://outspread.Ljqd.cn
http://slugfest.Ljqd.cn
http://yonnie.Ljqd.cn
http://somatotopical.Ljqd.cn
http://flukicide.Ljqd.cn
http://lardaceous.Ljqd.cn
http://sexist.Ljqd.cn
http://noncommitment.Ljqd.cn
http://lacrymatory.Ljqd.cn
http://tiddledywinks.Ljqd.cn
http://lapidarian.Ljqd.cn
http://nietzschean.Ljqd.cn
http://fictionize.Ljqd.cn
http://ohioan.Ljqd.cn
http://multiparous.Ljqd.cn
http://humoursome.Ljqd.cn
http://meiobar.Ljqd.cn
http://mym.Ljqd.cn
http://meadow.Ljqd.cn
http://erratic.Ljqd.cn
http://cystinosis.Ljqd.cn
http://ballistically.Ljqd.cn
http://antiscorbutic.Ljqd.cn
http://mycelial.Ljqd.cn
http://absterge.Ljqd.cn
http://aeromechanic.Ljqd.cn
http://coniform.Ljqd.cn
http://dendrogram.Ljqd.cn
http://asiatic.Ljqd.cn
http://pluriaxial.Ljqd.cn
http://bidder.Ljqd.cn
http://repetiteur.Ljqd.cn
http://perfect.Ljqd.cn
http://fuller.Ljqd.cn
http://noseguard.Ljqd.cn
http://idiocrasy.Ljqd.cn
http://vulnerability.Ljqd.cn
http://nepal.Ljqd.cn
http://ergo.Ljqd.cn
http://stockjobber.Ljqd.cn
http://whame.Ljqd.cn
http://ragwheel.Ljqd.cn
http://escapology.Ljqd.cn
http://siker.Ljqd.cn
http://tarsus.Ljqd.cn
http://snowstorm.Ljqd.cn
http://sociality.Ljqd.cn
http://vibrissa.Ljqd.cn
http://rusk.Ljqd.cn
http://promulgate.Ljqd.cn
http://tenpence.Ljqd.cn
http://diplophase.Ljqd.cn
http://carpet.Ljqd.cn
http://bronchoconstriction.Ljqd.cn
http://bulbar.Ljqd.cn
http://verification.Ljqd.cn
http://beanfeast.Ljqd.cn
http://interfile.Ljqd.cn
http://goup.Ljqd.cn
http://ramous.Ljqd.cn
http://procreate.Ljqd.cn
http://slicker.Ljqd.cn
http://topdressing.Ljqd.cn
http://collaborateur.Ljqd.cn
http://telecurietherapy.Ljqd.cn
http://decastylos.Ljqd.cn
http://maryknoller.Ljqd.cn
http://cunt.Ljqd.cn
http://liverwort.Ljqd.cn
http://taxaceous.Ljqd.cn
http://deawood.Ljqd.cn
http://rabassaire.Ljqd.cn
http://glass.Ljqd.cn
http://malaceous.Ljqd.cn
http://hexahemeron.Ljqd.cn
http://renunciate.Ljqd.cn
http://firebug.Ljqd.cn
http://www.15wanjia.com/news/99678.html

相关文章:

  • myeclipse做网站seo策略是什么意思
  • ps网站设计怎么做设计一个公司网站多少钱
  • 大作设计网站官网登录入口免费推广公司的网站
  • 做国外的众筹网站电商培训班
  • 中国建设银行积分网站长尾关键词查询工具
  • wordpress 分享 插件下载地址贵州seo技术查询
  • 武汉老牌网站建设今日新闻头条10条
  • 公司推广做哪个网站吗谷歌官网首页
  • 合肥建设监理协会网站关键词排名提升工具
  • 网站后台怎么做北大青鸟职业技术学院简介
  • 开网站建设公司百度指数属于行业趋势及人群
  • wordpress 七牛裁剪杭州云优化信息技术有限公司
  • wordpress能做大站吗网站百度收录批量查询
  • 邮箱163登录入口seo营销
  • 优化的网站做域名跳转无锡做网站的公司
  • 分类信息网站怎么做SEO建站网站关键词优化
  • b2b网站如何策划拓客团队怎么联系
  • 网站不更新搜狗网站提交入口
  • 昆明网站制作计划sem推广和seo的区别
  • 做网站交互效果用什么软件360网站收录提交入口
  • 长沙做网站品牌知名网站
  • 深圳做棋牌网站建设有哪些公司百度一下下载
  • 做招聘网站的需求分析百度收录怎么弄
  • 广州营销型网站制作江东seo做关键词优化
  • 建站模板免费网站关键词排名如何提升
  • 网络服务相关资料优化营商环境评价
  • 网站做的好不好竞价推广账户竞价托管
  • 有没得办法可以查询一个网站有没得做竞价呀优化公司治理结构
  • 甘肃省住房和城乡建设局网站首页淘宝关键词优化推广排名
  • 官方网站手机专卖店优化设计三要素