1.
s1 == s2 (true)
s2 == s3 (Most likely due to JVM optimization for strings of the same contents)
s1.equals(s2) (true)
s2.equals(s3) (true)
s1.compareTo(s2) (0)
s2.compareTo(s3) (0)
2. String s = new String("new string");
Answer: Correct
String s3 = s1 + s2;
Answer: Correct
String s3 = s1 - s2;
Answer: Incorrect
s1 == s2
Answer: Correct
s1 >= s2
Answer: Incorrect
s1.compareTo(s2);
Answer: Correct
int i = s1.length();
Answer: Correct
char c = s1(0);
Answer: Incorrect
char c = s1.charAt(s1.length);
Answer: Incorrect for two reasons:
· length should be length().
· It's out of bounds, even if the preceding problem is fixed.
3. Use the method equalsIgnoreCase.
4. Use the methods toLowerCase ot toUpperCase.
5. 0.
6. Use the overloaded static valueOf method in the String class.
7. A lowercase letter is between ‘a’ and ‘z’.
8. An alphanumeric character is between ‘0’ and ‘9’, or ‘A’ and ‘Z’, or ‘a’ and ‘z’.
9. Use the StringBuffer’s constructor to create a string buffer for a string, and use the toString method in StringBuffer class to return a string from a StringBuffer.
10. StringBuffer sb = new StringBuffer(s);
sb.reverse();
s = sb.toString();
11. StringBuffer sb = new StringBuffer(s);
sb.delete();
s = sb.toString();
12. It is actually an array.
13. StringTokenizer st = new StringTokenizer(s, "/\");
14. I
am
learning Java