String s ="abc";String s =newString("abc");s +="abc"; // s is new generated, this is a concatString a ="abc";String b ="abc";a == b; // true, because this way generated string means a constant value, when create b, system search "abc" first, then assign a address to b once find "abc" has been in memory.String a ="abc";String b =newString("abc");a == b; // false, addresses are differenta.equals(b); // compare values instead of addresses
char c ='a';
useful methods
s.length
s.length() s.substring(i, j) //=> [i, j), copy to a new string, T = O(n)s.concat("cde"); // s is new generateds +="cde"; // s is new generatedString upper =s.toUpperCase();// wrongs1 == s2 // if s1 is equal to s2, return 0, not true/false// rights1.equals(s2) // return true or falses1.split(" "); // separate String by " "s1.toCharArray(); // return a char array