DESKTOP-72IFJTH_20200909-赵亚军
1、问题:StringBuffer和StringBuilder一个表示线程安全的而另一个表示非线程安全的,什么时候应该用StringBuffer什么时候应该用StringBuilder??
2、例子:
StringBuffer buffer = new StringBuffer();
System.out.println( "capacity : " + buffer.capacity() + " , length : " + buffer.length() );
buffer.append( 100 );
buffer.append( true );
buffer.append( '\u0041' );
buffer.append( (char)66 );
buffer.append( "JPSB" );
****************************************************************
public static void main(String[] args) {
String s = "abc" ;
StringBuilder builder = new StringBuilder( s );
System.out.println( "length : " + builder.length() + " , capacity : " + builder.capacity() );
String x = builder.toString();
System.out.println( x == s );
System.out.println( builder );
builder.append( "你笑起来真好看" );
System.out.println( builder );
builder.delete( 0 , 3 ) ;
System.out.println( builder );
3、解决:
待解决
近期评论