字符串处理(3)常用构造函数

来源:互联网 发布:c 逆波兰算法 编辑:程序博客网 时间:2024/06/14 10:56

构造方法

使用说明

无构造方法

直接指向一个String对象

String()

创建一个空的String对象

StringString str

用已经存在的String对象复制一个String对象

StringStringBuffer buf

用已经存在的StringBuffer对象创建一个String对象

Stringchar c[]

用已经存在的字符数组创建一个String对象

String(byte[] b,String encoding)

用已经存在的字节数组创建一个String对象

 

String str1=new String("llll");

String str2=new String(str1);

System.out.println(str1+"?????");     //llll????

System.out.println(str2);                  //llll

       StringBufferbuffer=new StringBuffer("看看");

String str3=new String(buffer);

System.out.println(buffer);      //看看

System.out.println(str3);         //看看

 

char[] ds={'了','就'};

String str6=new String(ds);

System.out.println(str6);     //了就

 

byte[] bt={'b','y','t','e'};

String str7=new String(bt);

System.out.println(str7); //byte