Scanner
构造方法
public Scanner (InputSystem source);一般方法
hasNextXxx(); //hasNext();
nextXxx(); //next();
String
String s1 = "abc"; // 创建于常量池 (栈)
String s2 = "abc";
String s3 = new String("abc"); //创建于堆中(对象)
String s4 = new String("abc");
String s5 = "a"+"b"+"c"; // 编译时,优化为“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 |
|------------------------------------------------|
|不可变字符序列 |可变字符序列| 可变字符序列|
| |线程安全 | 线程不安全|
| |效率较低 | 效率较高|