I present to your attention one small question that we were asked at the so-called “flight” during training. There are trivial things in it, but there are also not so trivial ones, which is what I fell for. So, given the code, you need to write what will be output to the console and explain why.
public static void main(String[] args) { String s1 = "AB"; String s2 = "A" + "B"; String s3 = new String("AB"); System.out.println(s1 == s2); System.out.println(s1 == s3); System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3)); System.out.println(s1.toString() == s2); System.out.println(s1.equals(" AB".trim())); System.out.println("AB".equals("ab")); }
The first one who writes all the answers correctly (which I couldn’t) gets a cookie and a plus for karma :)
GO TO FULL VERSION