15-02-常用对象API(String类-构造函数)
2015-08-10 22:47
429 查看
package cn.itcast.string.demo; public class StringConstructDemo { public static void main(String[] args) { stringConstructDemo2(); } //用String构造器只能将两种数组能变成字符串,一种byte,一种char private static void stringConstructDemo2() { char[] arr = {'w','a','p','q','s'}; String s = new String(arr);//将数组连成字符串 String s1 = new String(arr,2,3);//从数组arr中角标为2的元素开始取,取3个元素,组成字符串 System.out.println("s="+s); System.out.println("s1="+s1); } private static void stringConstructDemo() { String s = new String();//等效于String s = "";不等效String s = null; byte[] arr = {65,66,67,68}; String s1 = new String(arr);//arr数组传进去,会自动根据数值查ASC码表 //真正开发时候有用,许多数据可变成字节存储,因为字节单位最小,而当需要观察这些数据时,可以将其转为字符串形式,一目了然 System.out.println("s1="+s1); } }
相关文章推荐
- 九度oj 1006
- mysql主从复制
- 详细介绍C/C++数组名与指针区别
- 程序员怎么一步步提高自己
- 内存管理器
- Linux(cent OS)下软件包管理-源码包与rpm包的区别
- 从一个R语言案例学线性回归
- selenium+pillow实现网站定点截图并插入邮件发送
- 跟着聪明人学习
- linux中fork()函数详解
- 15-01-常用对象API(String类-特点)
- 在小米应用商店提交app之攻略
- 各种排序方法及其比较
- iOS 越狱机免证书调试
- [问与答]为什么 'a' in ('abc') 是True 而 'a' in ['abc'] 是False呢?
- Android Navigation的使用
- Spring MVC 4值传递
- postgresql 用户的操作权限
- [问与答]为什么 'a' in ('abc') 是True 而 'a' in ['abc'] 是False呢?
- 使用getline读入