Java OCA OCP Practice Question 741

Question

Which of the following can fill in the blank so the following code prints true?

String v = " :) - (: "; 
String really = v.trim(); 
String question =                                 ; 
System.out.println(really.equals(question)); 
  • A. v.substring(0, v.length() - 1)
  • B. v.substring(0, v.length())
  • C. v.substring(1, v.length() - 1)
  • D. v.substring(1, v.length())


C.

Note

The trim() method returns a String with all leading and trailing white space removed.

In this question, that's the seven-character String: ":) - (:".

Options A and B are incorrect because they do not remove the first blank space in v.

Option D is incorrect because it does not remove the last character in v.

Option C is correct.




PreviousNext

Related