• JAVA_SE基础——62.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 count)  使用一个字符数组构建一个字符串, 指定开始的索引值,与使用字符个数。
    String(int[] codePoints,int offset,int count)
    String(String original) 

    public class Demo2 {
    	
    	public static void main(String[] args) {
    		String str = new String();//创建一个空内容的字符串对象  构造函数:String() 
    		byte[] buf = {97,98,99};
    		
    		str = new String(buf); //使用一个字节数组构建一个字符串对象    构造函数:String(byte[] bytes) 
    		str = new String(buf,1,2);   //使用一个字节数组构建一个字符串对象,指定开始解码 的索引值和解码的个数。
    		//使用的构造函数是:String(byte[] bytes, int offset, int length) 
    		char[] arr = {'明','天','是','圣','诞'};
    		str = new String(arr); //使用字符数组构建一个字符串    String(char[] value)
    		str = new String(arr,3,2);//使用了String(char[] value, int offset, int count)  构造函数
    		
    		int[] buf2 = {65,66,67};
    		str = new String(buf2,0,3);//使用了 	String(int[] codePoints,int offset,int count) 构造函数
    		
    		str = new String("abc");//使用了	String(String original)   构造函数
    		
    		System.out.println("字符串的内容:"+str);
    			
    	}
    	
    }



    交流企鹅:654249738,和自学者交流群:517284938

  • 相关阅读:
    sqoop导出数据
    sqoop导入数据
    Hive学习(二)
    各个版本的集群安装包地址
    Hive学习(一)
    数据仓库
    HBase学习(二)
    HBase学习(一)
    MySQL中阻塞
    MySQL中锁问题
  • 原文地址:https://www.cnblogs.com/Jhaiha0/p/8465279.html
Copyright © 2020-2023  润新知