StringBuffer 的 各种方法】的更多相关文章

package hello; import java.util.Scanner; public class 实验五 { public static void main(String[] args) { // TODO Auto-generated method stub char cc[]={'a','b','c','d','e','f'}; //将字符串数组转成string String s1 =String.copyValueOf(cc); System.out.println(s1); /…
List的add方法与addAll方法 区别 add add是将传入的参数作为当前List中的一个Item存储,即使你传入一个List也只会另当前的List增加1个元素 addAll addAll是传入一个List,将此List中的所有元素加入到当前List中,也就是当前List会增加的元素个数为传入的List的大小 分析 List result = new ArrayList(); // add(int index,Elelemt e)把list中的每一个元素加到result中,result.…
StringBuffer 其实提供了很多有用的方法, 以前用的多是 append, 其实还有: append(double) delete(int, int) deleteCharAt(int) replace(int, int, String) substring(int) subSequence(int, int) substring(int, int) insert(int, char[], int, int) insert(int, Object) insert(int, String)…
一.String类的方法 public char charAt(int index)          返回字符串index个字符 public int length()         返回字符串长度 public int indexof(String str)        返回字符串中出现str的第一个位置 public int indexof(String str, int fromIndex)      返回字符串中从fromIndex开始出现str的第一个位置 public bool…
public static void testAppend() { StringBuffer sb = new StringBuffer("This is a StringBuffer!"); sb.append(1.23f); System.out.println(sb.toString()); } 输出的是This is a StringBuffer!1.23f 关于StringBuffer对象的append方法介绍,在Ivor Horton所著的<Java 2 入门经典(J…
delete方法与deleteCharAt两个方法都是用来删除StringBuffer字符串指定索引字符的方法, delete(int  begin,int  end)有两个参数,使用时删除索引从begin开始(包含begin)到end(不包含end)的所有字符: deleteCharAt(int  index)只有一个参数,使用时删除索引为index的字符:…
在字符串的连接过程中StringBuffer的效率要比String高: string操作代码: String str = new String("welcome to "); str += "here"; 如上代码实际上是通过建立一个StringBuffer,让后台调用append(),最后再将StringBuffer toSting();这样的话String的连接操作就比StringBuffer多出了一些附加操作,当然效率上要打折扣.并且由于String 对象是不…
String: String类的对象是一经创建就无法变动内容的字符串常量,创建String类的对象可以使用直接赋值和利用构造方法赋值 String str=“hello”;  String str=new String("hello");两种方法都可以 String类的常用方法, length() //返回字符串的长度 charAt( index )   //返回当前字符串index下标处的字符 indexOf( ch )        //返回指定字符在此字符串中第一次出现的索引 s…
public class Page116 { /** * StringBuffer类的练习 * @param args * @throws IOException */ public static void main(String[] args) throws IOException { StringBuffer sb1=new StringBuffer(); StringBuffer sb2=new StringBuffer(30); StringBuffer sb3=new StringBu…
Stringbuffer是动态字符串数组,append( )是往动态字符串数组添加,跟“xxxx”+“yyyy”相当‘+’号. 跟String不同的是Stringbuffer是放一起的,String1+String2和Stringbuffer1.append("yyyy")虽然打印效果一样,但在内存中表示却不一样. String1+String2 存在于不同的两个地址内存,Stringbuffer1.append(Stringbuffer2)放再一起. 例如: StringBuffer…