Question : Please look into given code fragement. Which of the following conditional statement will help you to print Equal ? 1. String firstString = secondString; if(firstString==secondString) 2. if(firstString.equlaIgnoreCase(secondString)) 3. String thirdString = secondString; if(firstString.equals(thirdString)); 4. if(firstString.toLowerCase() == str2.toLowerCase())
Correct Answer : 2
Question : You have been given below code fragement
StringBuilder sb = new StringBuilder ( ) ; sb.append ("world");
Correct Answer : 1 Exp: The java.lang.StringBuilder.insert(int offset, char c) method inserts the string representation of the char argument into this sequence. The second argument is inserted into the contents of this sequence at the position indicated by offset. The length of this sequence increases by one. The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.
Question : Given the code fragment: String h1 = "Bob"; String h2 = new String ("Bob"); What is the best way to test that the values of h1 and h2 are the same?
1. if (h1 = = h2) 2. if (h1.equals(h2)) 3. if (h1 = = h2) 4. if (h1.same(h2))
Correct Answer : 2 Explanation: The equals method compares values for equality