String的构造方法

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);
		
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值