thinking in java筆記 13 字串操作

來源:互聯網
上載者:User

***不可變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()實現字串的格式化
***Regex
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.