黑马程序员技术交流社区

标题: String类常见的构造方法 [打印本页]

作者: cxl1694095035    时间: 2016-5-13 16:08
标题: String类常见的构造方法
//String类常见的构造方法
        public static void main(String[] args) {
                String s1 = new String();                                //空参构造
                System.out.println(s1);
               
                byte[] arr1 = {97,98,99};                                //把子节数组转成字符串
                String s2 = new String(arr1);
                System.out.println(s2);
               
                byte[] arr2 ={48,49,50,60,70,80,90};
                String s3 = new String(arr2,2,3);                //从arr2字符数组2索引开始转3个
                System.out.println(s3);
               
                char[] arr3 = {'a','b','c','d','e','f'};//将字符数组转成字符串
                String s4 = new String(arr3);
                System.out.println(s4);
               
                String s5 = new String(arr3,1,3);                //件arr3字符数组,从1索引开始转3个
                System.out.println(s5);
               
                String s6 = new String("haoma");                //把字符串常量转成字符串
                System.out.println(s6);
        }

}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2