Oracle
1Z0-803 · Question #194
Given: public class MyClass { public static void main(String[] args) { String s = " Java Duke "; int len = s.trim().length(); System.out.print(len); } } What is the result?
The correct answer is B. 9. Java-String trim() Method This method returns a copy of the string, with leading and trailing whitespace omitted.
Working with Selected Classes from the Java API
Question
Given:
public class MyClass { public static void main(String[] args) { String s = " Java Duke "; int len = s.trim().length(); System.out.print(len); } } What is the result?
Options
- A8
- B9
- C11
- D10
- ECompilation fails
How the community answered
(62 responses)- A2% (1)
- B94% (58)
- C2% (1)
- E3% (2)
Explanation
Java-String trim() Method This method returns a copy of the string, with leading and trailing whitespace omitted.
Topics
#String methods#trim()#length()
Community Discussion
No community discussion yet for this question.