博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java.lang.StringBuilder
阅读量:5741 次
发布时间:2019-06-18

本文共 2131 字,大约阅读时间需要 7 分钟。

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( 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 hasb.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.

 

 

 

 

 

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

转载于:https://www.cnblogs.com/YKang/p/7275670.html

你可能感兴趣的文章
“亲切照料”下的领域驱动设计
查看>>
SRE工程师到底是做什么的?
查看>>
解读:Red Hat为什么收购Ansible
查看>>
PHP json_encode() 函数介绍
查看>>
js动态设置元素高度
查看>>
Ossim下的安全合规管理
查看>>
DelphiWebMVC框架下BPL热部署实现
查看>>
C++与MySQL的冲突
查看>>
siki学习之观察者模式笔记
查看>>
单元测试
查看>>
spring.net 继承
查看>>
ES6:模块简单解释
查看>>
JavaScript indexOf() 方法
查看>>
用Bootstrap写一份简历
查看>>
ZJU PAT 1023
查看>>
WMI远程访问问题解决方法
查看>>
从零开始学习IOS,(UILabel控件)详细使用和特殊效果
查看>>
Android开发历程_15(AppWidget的使用)
查看>>
阿花宝宝 Java 笔记 之 初识java
查看>>
7、设计模式-创建型模式-建造者模式
查看>>