nerdexam
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)
  • A
    5% (1)
  • B
    75% (15)
  • C
    5% (1)
  • E
    15% (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.

Full 1Z0-809 Practice