黑马程序员技术交流社区

标题: 代码练习 [打印本页]

作者: 冬冬宋    时间: 2016-8-10 22:50
标题: 代码练习
[AppleScript] 纯文本查看 复制代码
String s = new String();        //public String():空构造
                System.out.println(s);
               
                byte [] arr = {97,98,99};//public String(byte[] bytes):把字节数组转成字符串(下面是用法)
                String s1 = new String(arr);
                System.out.println(s1);//结果是abc
               
                byte [] arr1 = {97,98,99,100,101,102,103,104};//public String(byte[] bytes,int index,int length):把字节数组的一部分转成字符串
                String s2 = new String(arr1,2,4);//将数组中的数据,从索引值为2的开始,转换成字符串,一共连续转换4个
                System.out.println(s2);//结果是cdef
               
                char [] arr2 = {'a','b','b','c','d'};//public String(char[] value):把字符数组转成字符串
                String s3 = new String(arr2);
                System.out.println(s3);//最后输出的是:abbcd这样的字符串
               
                char [] arr3 = {'a','b','c','d','e'}; //public String(char[] value,int index,int count):把字符数组的一部分转成字符串
                String s4 = new String(arr3,2,3);//把索引2开始的字符数转换成字符串,转换3个
                System.out.println(s4);//结果是cde
               
                String s5 = "abcdr";//public String(String original):把字符串常量值转成字符串       
                String s6 = new String(s5);
                System.out.println(s5);

作者: 冬冬宋    时间: 2016-8-10 22:52
22222222222222222




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