1 public class helloworld
2 {
3 public static void main(String[] args)
4 {
5 //字符串的两种定义方式 第一种 String a="abcdef"; 第二种String c=new String("abcdef");
6 String a="abcdef";
7 char [] b={'a','b','c','d','e','f'};//char数组
8 String c=new String(b);//第二种用于把char类型转换String类型
9 String d="abcdef";
10 String e=new String("abcdef");
11 //比较
12 System.out.println(a==c);//普通字符串与new出来的字符串比较会返回false
13 System.out.println(a.equals(c));//普通字符串与new出来的字符串用equals比较才会返回true
14 System.out.println(a==d);//普通字符串与普通字符串比较会返回true
15 System.out.println(c==e);//new出来字符串与new出来字符串比较会返回false
16 System.out.println(c.equals(e));//new出来字符串与new出来字符串用equals比较才会返回true
17
18 }
19 }