zoukankan      html  css  js  c++  java
  • java.lang.StringBuilder

    StringBuilder 类是可修改的字符串类,内部由可变数组构成,如果需要频繁修改字符串,字符串追加等,最好使用此类

    此类只能在单线程中使用,但效率较高,如果要在多线程中使用,用StringBuffer类,两类API完全相同

    Constructor 

      StringBuilder();   Constructs a string builder with no characters in it and an initial capacity of 16 characters.

      StringBuilder(String str);   Constructs a string builder initialized to the contents of the specified string.

    Method:

    追加

      StringBuilder apend(int i);          // append are overloaded so as to accept data of any type. 

      Appends the string representation of the int argument to the sequence.

      StringBuilder append(CharSequence s, int start, int end)

      Appends a subsequence of the specified CharSequence to this sequence

      

    StringBuilder sb = new StringBuilder("h");
    sb.append("a");    // sb is ha
    sb.append("_hahehe", 1, 3);  // sb is haha

     插入

      StringBuilder insert(int offset, double d)   // insert are overloaded so as to accept data of any type. 

      Inserts the string representation of the double argument into this sequence.

    获取值

      char charAt(int index)

      Returns the char value in this sequence at the specified index.

    删除

      StringBuilder delete(int start, int end)

      Removes the characters in a substring of this sequence  

      StringBuilder deleteCharAt(int index)  

      Removes the char at the specified position in this sequence.

    查找

      int indexOf(String str, int fromindex)     //indexOf(String str)   lastIndexOf 等同String

      Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

    长度

      int length()

    替换

      StringBuilder replace(int start, int end, String str)  

      Replaces the characters in a substring of this sequence with characters in the specified String.

    修改

      void setCharAt(int index, char ch)

      The character at the specified index is set to ch.

    反转

      StringBuilder reverse()

      Causes this character sequence to be replaced by the reverse of the sequence

    子字符串

      String subString(int start, int end)         

      Returns a new String that contains a subsequence of characters currently contained in this sequence.

      

      String toString()

      Returns a string representing the data in this sequence.

    ---恢复内容结束---

    WE ARE ALL IN THE GUTTER, BUT SOME OF US ARE LOOKING AT THE STARS
  • 相关阅读:
    Registering a Visual Studio .Net AddIn without an Installer
    广州的.Net Fans俱乐部的T恤和Logo的设计
    模板控件概念(转)
    随笔-在广州.Net俱乐部的一个下午
    快速备份Outlook中的资料
    web.config文件详解
    使用RAPI库操作移动设备——C#语言描述 (转贴)
    Ready to Rock 撼动未来:SQL Server 2005 ,Visual Studio 2005, BizTalk Server 2006 新品发布会 报名
    IBM Rational Solutions V2003
    VS.Net 2003 IDE 插件开发指南
  • 原文地址:https://www.cnblogs.com/YKang/p/7275670.html
Copyright © 2011-2022 走看看