Oracle
1Z0-809 · Question #177
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. 8. trim removes all whitespaces, this will create the String "JavaDuke" which contains 8 characters
Java Class Design
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
- A11
- B8
- C10
- DCompilation fails.
- E9
How the community answered
(20 responses)- A5% (1)
- B75% (15)
- C5% (1)
- E15% (3)
Explanation
trim removes all whitespaces, this will create the String "JavaDuke" which contains 8 characters
Topics
#String.trim()#String.length()#String API#whitespace handling
Community Discussion
No community discussion yet for this question.