Scanner
構(gòu)造方法
public Scanner (InputSystem source);一般方法
hasNextXxx(); //hasNext();
nextXxx(); //next();
String
String s1 = "abc"; // 創(chuàng)建于常量池 (棧)
String s2 = "abc";
String s3 = new String("abc"); //創(chuàng)建于堆中(對(duì)象)
String s4 = new String("abc");
String s5 = "a"+"b"+"c"; // 編譯時(shí),優(yōu)化為“abc”
String s6 = 'a'+'b'+'c'; //???
String t = "a"+"b";
String s7 = t+"c"; //???
System.out.println(s1==s2); //true
System.out.println(s1==s5); //true
System.out.println(s1==s3); //false
System.out.println(s3==s4); //false
System.out.println(s1==s7); //???
| String | StringBuffer | StringBuilder |
|------------------------------------------------|
|不可變字符序列 |可變字符序列| 可變字符序列|
| |線程安全 | 線程不安全|
| |效率較低 | 效率較高|