当前位置: 代码迷 >> 综合 >> JDK源码之——StringBuilder
  详细解决方案

JDK源码之——StringBuilder

热度:45   发布时间:2023-10-21 12:08:08.0

部分方法没有解释,有疑问或错误的地方,欢迎评论指出

观看本文章之前,建议观看JDK源码之——AbstractStringBuilder

import java.util.stream.IntStream;/*** StringBuilder主要继承 抽象类AbstractStringBuilder 类* 很多实现方法在AbstractStringBuilder中,关于详解 点击下面链接*/
// https://blog.csdn.net/qq_34926773/article/details/88706719
public final class StringBuilderextends AbstractStringBuilderimplements java.io.Serializable, CharSequence
{/** Java的序列化机制是通过判断类的serialVersionUID来验证版本一致性的 */static final long serialVersionUID = 4383685877147921099L;/*** AbstractStringBuilder(int capacity) {value = new char[capacity];}*/public StringBuilder() {super(16);}public StringBuilder(int capacity) {super(capacity);}/*** 扩容* 拼接字符*/public StringBuilder(String str) {super(str.length() + 16);append(str);}public StringBuilder(CharSequence seq) {this(seq.length() + 16);append(seq);}@Overridepublic java.lang.StringBuilder append(Object obj) {return append(String.valueOf(obj));}/*** super.append() == AbstractStringBuilder 的 public AbstractStringBuilder append(String str)* 返回原对象引用* @param str* @return*/@Overridepublic java.lang.StringBuilder append(String str) {super.append(str);return this;}public java.lang.StringBuilder append(StringBuffer sb) {super.append(sb);return this;}@Overridepublic java.lang.StringBuilder append(CharSequence s) {super.append(s);return this;}/*** @throws     IndexOutOfBoundsException {@inheritDoc}*/@Overridepublic java.lang.StringBuilder append(CharSequence s, int start, int end) {super.append(s, start, end);return this;}@Overridepublic java.lang.StringBuilder append(char[] str) {super.append(str);return this;}/*** @throws IndexOutOfBoundsException {@inheritDoc}*/@Overridepublic java.lang.StringBuilder append(char[] str, int offset, int len) {super.append(str, offset, len);return this;}@Overridepublic java.lang.StringBuilder append(boolean b) {super.append(b);return this;}@Overridepublic java.lang.StringBuilder append(char c) {super.append(c);return this;}@Overridepublic java.lang.StringBuilder append(int i) {super.append(i);return this;}@Overridepublic java.lang.StringBuilder append(long lng) {super.append(lng);return this;}@Overridepublic java.lang.StringBuilder append(float f) {super.append(f);return this;}@Overridepublic java.lang.StringBuilder append(double d) {super.append(d);return this;}/*** @since 1.5*/@Overridepublic java.lang.StringBuilder appendCodePoint(int codePoint) {super.appendCodePoint(codePoint);return this;}@Overridepublic String toString() {return null;}@Overridepublic IntStream chars() {return null;}@Overridepublic IntStream codePoints() {return null;}
}

 

  相关解决方案