字符串类型:String
- String属于引用数据类型,翻译为:字符串
- 声明String类型变量时,使用一对””
- 使用方式与基本数据类型一致。
例如:String str = “abcd”; //可包含0—-多个字符;char必须放一个字符;
- String可以和8种基本数据类型变量做运算,且运算只能是连接运算:+
- 运算的结果仍然是String类型
char c = 'a';//a:97 A:65int num = 10;String str = "hello";System.out.println(c + num + str);//107helloSystem.out.println(c + str + num);//ahello10System.out.println(c + (num + str));//a10helloSystem.out.println((c + num) + str);//107helloSystem.out.println(str + num + c);//hello10aSystem.out.println("* *");System.out.println('*' + '\t' + '*'); //char+char+char=93------>自身相加为intSystem.out.println('*' + "\t" + '*'); //char+string+char=* *System.out.println('*' + '\t' + "*"); //char+char+string=51*System.out.println('*' + ('\t' + "*")); //char+(char+string)=* *
