package date0812;
import java.io.ByteArrayOutputStream;
import java.nio.ByteOrder;
/*
* 字符串:由多个字符组成一串数据。
* String s = "hello";
*
* 构造方法:
* String()
* String(byte[] bytes)
* String(byte[] bytes, int index, int length)
* String(char[] value)
* String(char[] value, int index, int length)
* String(String str)
* 直接给字符串对象赋值。
*
* 成员方法:
* public int length():获取字符串的长度
*/
public class StringDemo1 {
public static void main(String[] args) {
// String = "HelloWroldOver";
String str = new String();
System.out.println(str);
System.out.println(str.length());
System.out.println("-------------");
// * String(byte[] bytes)
byte [] by = {102, 103,104,105,106};
String by2 = new String(by);
System.out.println(by2);
System.out.println(by2.length());
System.out.println("-------------");
// * String(byte[] bytes, int index, int length)
byte [] b = {102, 103,104,105,106};
String b1 = new String(b,0,5);
System.out.println(b1);
System.out.println(b1.length());
}
}
|
|