StringBuilder


原文:

public final class StringBuilder
extends Object
implements Serializable, CharSequence
A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.
For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet".
In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x).
Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that StringBuffer be used.
Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

译:

StringBuilder是在使用单线程时StringBuffer的替代品,StringBuilder没有同步的权限,再涉及多线程时,还是要继续使用StringBuffer。Method:方法主要有两个:
StringBuilder sb = new StringBuild();
1.sb.append(str);
2.sb.insert(position,str);

tips:当参数为null时,会报空指针异常。

转载于:https://www.cnblogs.com/kongieg/p/10628450.html

Lang.String相关推荐

  1. java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean java.lang.String.equals(j

    今天切正式环境出现的空指针 记录一下 下面是错误 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean j ...

  2. JDK1.8源码(三)——java.lang.String 类

    String 类也是java.lang 包下的一个类,算是日常编码中最常用的一个类了,那么本篇博客就来详细的介绍 String 类. 1.String 类的定义 public final class ...

  3. mybaits错误解决:There is no getter for property named 'parentId ' in class 'java.lang.String'

    在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名. 比如mapper中如下方法,只有一个String值 publ ...

  4. ArrayMap java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]

    错误堆栈: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Object[]at android. ...

  5. 完美解决Invalid layout of java.lang.String at value问题的方法

    完美解决Invalid layout of java.lang.String at value问题的方法 参考文章: (1)完美解决Invalid layout of java.lang.String ...

  6. mybatis中传集合时 报异常 invalid comparison: java.util.Arrays$ArrayList and java.lang.String

    mybatis中传集合时 报异常 invalid comparison: java.util.Arrays$ArrayList and java.lang.String 参考文章: (1)mybati ...

  7. java.lang.date_无法将java.lang.String类型的值转换为必需类型java.util.Date

    from date: to date: Trouver 这是控制器代码部分: @RequestParam(name = "d1", defaultValue = "190 ...

  8. 在拦截器中获取请求参数,[Ljava.lang.String; cannot be cast to java.lang.String报错

    Map<String,Object> parametersmap=invocation.getInvocationContext().getParameters();//获取请求参数    ...

  9. Java报错:java.math.BigDecimal cannot be cast to java.lang.String

    从数据库取数字,转为string,报错: java.math.BigDecimal cannot be cast to java.lang.String 错误代码 Integer.parseInt(( ...

  10. “无效数字” ;java.lang.Integer cannot be cast to java.lang.String

    今天页面上突然查询不出数据,大致的sql语句是 select xx ,xxx from table a where a.lrmb in ( 6101060033, 61010503300, 61016 ...

最新文章

  1. wireshark: no interface can be used for capturing in this system
  2. linux编译c 优化,Linux编译选项
  3. windows安装python库_Windows安装Python机器学习包
  4. Codeblocks 中文乱码解决方法
  5. [BZOJ]3727: PA2014 Final Zadanie
  6. atomicReference 的使用和AtomicStampedReference 解决ABA的问题
  7. linux添加windows隐藏属性,解决文件夹隐藏属性无法取消的办法
  8. 将World中的向下箭头替换为回车符
  9. Java找不到对象的警告_程序猿的24个段子:程序员找不到对象 一般有三种情况...
  10. 2021年东南大学软件学院电子信息考研信息
  11. 天梯赛 - 一个整数“犯二的程度”定义为该数字中包含2的个数与其位数的比值。如果这个数是负数,则程度增加0.5倍;如果还是个偶数,则再增加1倍。例如数字
  12. 跑跑卡丁车,网络中断问题
  13. 读《Machine Learning Done Wrong》(机器学习易犯错误)有感
  14. 实战PyQt5: 141-QChart图表之箱形图
  15. 用户权限集中管理方案
  16. 【内部类、匿名内部类、API】的学习
  17. java透明度_简单的透明度示例不适用于Java 3D
  18. 无参考图像评价指标NIQE——自然图像质量
  19. ctfshow 萌新计划 writeup1-8
  20. Spring系列学习之Spring Mobile

热门文章

  1. python一般学多久可以考试_为何Python适合初学者 一般Python要学习多久
  2. 进程间通信IPC(二)(共享内存、信号、信号量)
  3. 数据库---JDBC
  4. Docker-machine创建虚机时停在虚机启动的提示上,并且创建的虚机显示Ip Not found...
  5. SVN四部曲之SVN设置详解深入
  6. bzoj2751[HAOI2012]容易题(easy)
  7. css改变谷歌浏览器的滚动条样式
  8. sql多表查询之一:Where 和 On的秘密
  9. 解析邮件归档技术 保护企业邮件安全(三)
  10. 系出名门Android(7) - 控件(View)之ZoomControls, Include, VideoView, WebView, RatingBar, Tab