1.String属于引用数据类型,可以和8种基本数据类型坐运算,且只能是连接运算: +
package com.yl.pdfdemo.day01;
/**
* @Author wfj
* @Date 2021/1/9
* @Description String的使用
* @Version 1.0
*/
public class StringTest {
public static void main(String[] args) {
/**
* String属于引用数据类型,值要用""包起来
* String可以和8种基本数据类型做运算,且运算只能是连接运算: +
* 运算的结果是String类型
*
*/
String s = "hello";
String s1 = "a";
String s2 = "";
System.out.println(s);
System.out.println(s1);
System.out.println(s2);
//编译不会通过
//char c = '';
int number = 18;
String s3 = "年龄";
String info = number + s3;
System.out.println(info);
Boolean b = true;
String info1 = info + b;
System.out.println(info1);
char c = 'a';
int age = 10;
String str = "age";
System.out.println(c + age + str);// 107age
System.out.println(c + str + age);// aage10
System.out.println(c + (age + str));// a10age
System.out.println((c + age) + str);// 107age
System.out.println(str + age + c);// age10a
//打印 * *
System.out.println("* *");// * *
System.out.println('*' + '\t' + '*'); // 93
System.out.println('*' + "\t" + '*');// * *
System.out.println('*' + '\t' + "*");// 51*
System.out.println('*' + ('\t' + "*"));//* *
//********************
// 编译不会通过
//String str2 = 123;
String str1 = 123 + "";
System.out.println(str1);
//编译不会通过,不能这样转换
//int a = (int)str1;
int i = Integer.parseInt(str1);
System.out.println(i);
}
}