package com.heilong.string;
/*
* String构造方法
*
* String() 创建一个空内容的字符串对象
* String(byte[] bytes) 使用一个字节数组构建一个字符串对象
* String(byte[] bytes, int offset, int length)
* bytes:要解码的数组
* offset:指定从数组中哪个索引值开始解码
* length:要解码多少元素
* String(char[] value) 使用一个字符数组构建一个字符串
* String(char[] value, int offset, int length) 使用一个字符数组构建一个字符串,指定开始解码的索引值和解码的个数
* String(int[] codePoints, int offset, int count)
* String(String original)
* */
public class Demo2 {
public static void main(String[] args) {
String str = new String();
byte[] buf = {97,98,99};
str = new String(buf); //使用一个字节数组构建一个字符串对象
str = new String(buf,1,2); // 使用一个字节数组构建一个字符串对象,指定开始解码的索引值和解码的个数
char[] arr = {'明','天','是','圣','诞'};
str = new String(arr);
str = new String(arr,3,2);
int[] buf2 = {65,66,67};
str = new String(buf2,0,3);
System.out.println("字符串的内容 " + str);
}
}
String的构造方法
最新推荐文章于 2023-05-29 08:11:25 发布