下面代碼將輸出什麼內容:(false)java
public class SystemUtil{ public static boolean isAdmin(String userId){ return userId.toLowerCase()=="admin"; } public static void main(String[] args){ System.out.println(isAdmin("Admin")); } }
true
false
1
編譯錯誤
首先要知道toLowerCase()的底層實現是code
return new String(result, 0, len + resultOffset);
System.out.println("aaa" == "aaa"); // true System.out.println("aaa" == new String("aaa")); //false System.out.println(new String("aaa") == new String("aaa")); //false