thinking in java笔记 13 字符串操作

***不可变String

    String类中的每个看起来会修改String值的方法,实际上是创建了新的String对象。
***StringBuilder
    简单的字符串操作可以使用java的操作符+,复杂的字符串拼接等操作(比如有循环),应优先采用StringBuilder,因为如果采用默认操作符,在循环体内,java编译器会在每次循环时new一个StringBuilder来操作字符串,效率会低。
***格式化输出
        public class SimpleFormat {
public static void main(String[] args) {
int x = 5;
double y = 5.332542;
// The old way:
System. out .println( "Row 1: [" + x + " " + y + "]" );
// The new way:
System. out .format( "Row 1: [%d %f]\n" , x, y);
// or
System. out .printf( "Row 1: [%d %f]\n" , x, y);
}
} /* Output:
Row 1: [5 5.332542]
Row 1: [5 5.332542]
Row 1: [5 5.332542]

    java.util.Formatter类实现新的格式化功能
    String.format()实现字符串的格式化

***正则表达式

原文地址:https://www.cnblogs.com/myparamita/p/2203977.html