package cn.itcast.myString;
import cn.itcast.Person;
/*
* String转换:
* 1:重写了Object的toString方法,返回这个字符串本身的数值
* 2:public static String copyValueOf(char[] data, 返回指定数组中表示该字符序列的 String。
int offset, //从哪开始
int count) //取多少个
3:public static String valueOf(boolean b或其他基本类型) 基本类型直接转成引用类型
4:public static String valueOf(char[] data,int offset,int count)
5:public static String valueOf(Object obj)
注意:
字符数组特殊性:打印时,结果不是地址,而是值
*/
public class Demo7 {
public static void main(String[] args) {
//2:
char[] cArr = {97,98,99};
String copyValueOf = String.copyValueOf(cArr,1,2);
System.out.println(copyValueOf);
//3:public static String valueOf(boolean b或其他基本类型)
String valueOf = String.valueOf(true);
System.out.println(valueOf);
//4:public static String valueOf(char[] data,int offset,int count)
char[] cArr2 = {'a','b','c'};
String valueOf2 = String.valueOf(cArr2, 0, cArr2.length);
System.out.println(valueOf2);
//5:public static String valueOf(Object obj)
Person p = new Person();
String valueOf3 = String.valueOf(p);
System.out.println(valueOf3);
int[] iArr = {1,2,3,4};
char[] cArr3 = {'a','b','g','s'};
String valueOf4 = String.valueOf(iArr);
String valueOf5 = String.valueOf(cArr3);
System.out.println(valueOf4);
System.out.println(valueOf5);
}
}
|
|