StringBuilder详解

2023-12-20 16:59:00

1、 线程不安全


    public StringBuilder append(CharSequence s, int start, int end) {
        super.append(s, start, end);
        return this;
    }

2、每个方法都是返回自己的对象,所以可以串行化的调用。


    public StringBuilder append(CharSequence s, int start, int end) {
        super.append(s, start, end);
        return this;
    }


    public StringBuilder append(char[] str) {
        super.append(str);
        return this;
    }

    public StringBuilder append(char[] str, int offset, int len) {
        super.append(str, offset, len);
        return this;
    }

 
    public StringBuilder append(boolean b) {
        super.append(b);
        return this;
    }

    @Override
    public StringBuilder append(char c) {
        super.append(c);
        return this;
    }

    @Override
    public StringBuilder append(int i) {
        super.append(i);
        return this;
    }

    @Override
    public StringBuilder append(long lng) {
        super.append(lng);
        return this;
    }

    @Override
    public StringBuilder append(float f) {
        super.append(f);
        return this;
    }

    @Override
    public StringBuilder append(double d) {
        super.append(d);
        return this;
    }

   
    public StringBuilder appendCodePoint(int codePoint) {
        super.appendCodePoint(codePoint);
        return this;
    }

    public StringBuilder delete(int start, int end) {
        super.delete(start, end);
        return this;
    }

3、可以设置容量

 public StringBuilder() {
        super(16);
    }

  
    public StringBuilder(int capacity) {
        super(capacity);
    }

使用中一定要注意它的特性。

文章来源:https://blog.csdn.net/henanchina/article/details/135109964
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。