String StringBuffer StringBuilder

原创 2015年07月09日 23:52:56

The String class represents character string. All string literals in java program are implemented as instances of this class. 

Strings are constant, their values cannot be changed after they are created. Because String objects are immutable, they can be shared.

String concatenation is implemented through the StringBuilder and StringBuffer class and its append method.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

StringBuffer class is a thread-save, mutable sequence of characters. A string buffer is like a string, but can be modified. String buffers are safe to use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is  consistent with the order of the method calls made by each of the individual threads involved.

StringBuilder is also 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, as it supports all of the same operations but it is faster, as it performs no synchronization.


package stringtest; public class StringOpera { public static void main(String[] args) { Strin...
  • u012768347
  • u012768347
  • 2017年03月12日 16:33
  • 336

Java String为什么是不可变类,StringBuffer与StringBuilder区别

熟悉Java的都知道String类是不可变,但String类为什么设计成不可变类,如何做到不可变没有仔细想过。 String为什么设计成不可变类? 1.Java字符串池的设计方式。     Strin...
  • chenchaofuck1
  • chenchaofuck1
  • 2016年03月10日 15:15
  • 2048


1 String、StringBuffer与StringBuilder (1)String 字符串常量; /** Strings are constant; their values cann...
  • chenliguan
  • chenliguan
  • 2016年07月14日 18:35
  • 5925

String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?

本内容是我从各处转载整理得来,是我的学习笔记,如有涉及到版权问题,请给我留言。 或者内容中有不正确的地方,也请各位大神能帮我指出更改,谢谢! 一、区别 1、String是字符串常量,而String...
  • dorapan1987
  • dorapan1987
  • 2015年03月17日 20:36
  • 888

StringBuffer 与 StringBuilder 区别与联系及源码分析

StringBuffer和StringBuilder的共同点: 1、都是用于操作字符串,使用这两个而不使用String的原因是因为String是Final类型,当对字符串操作较多时采用Str...
  • u010854517
  • u010854517
  • 2017年03月08日 10:07
  • 196


  • u012859193
  • u012859193
  • 2014年04月26日 11:15
  • 2252

Java中字符串探索—-String ,StringBuffer ,StringBuilder及字符串缓存池

转载来自: 字符串是编程中应用到最多的一个数据类型,简单实用,但是深入理解它们,会给我们带来更多好处。 字符串缓...
  • shehun11
  • shehun11
  • 2015年09月02日 11:56
  • 464


Java中的String类是一个很常用,但最不注意其细节的类,因此大多数面试会那这个类做文章。比如String str = new String("hello");开辟了几个内存空间,String和S...
  • xiangbudao8
  • xiangbudao8
  • 2016年05月25日 18:12
  • 167


public final classStringBuffer(StringBuilder) extends AbstractStringBuilder
  • qq_33824312
  • qq_33824312
  • 2017年03月13日 17:40
  • 238


String 字符串常量 StringBuffer 字符串变量(线程安全) StringBuilder 字符串变量(非线程安全)  简要的说, String 类型和 StringBuffer 类...
  • u014086926
  • u014086926
  • 2016年07月29日 22:28
  • 7916
您举报文章:String StringBuffer StringBuilder