nerdexam
Oracle

1Z0-803 · Question #24

Which statement initializes a stringBuilder to a capacity of 128?

The correct answer is D. StringBuildersb = new StringBuilder(128);. Constructs a string builder with no characters in it and an initial capacity specified by the capacity Note: An instance of a StringBuilder is a mutable sequence of characters. The principal operations on a StringBuilder are the append and insert methods, which are overloaded so

Working with Selected Classes from the Java API

Question

Which statement initializes a stringBuilder to a capacity of 128?

Options

  • AStringBuildersb = new String("128");
  • BStringBuildersb = StringBuilder.setCapacity(128);
  • CStringBuildersb = StringBuilder.getInstance(128);
  • DStringBuildersb = new StringBuilder(128);

How the community answered

(51 responses)
  • A
    4% (2)
  • B
    2% (1)
  • C
    2% (1)
  • D
    92% (47)

Explanation

Constructs a string builder with no characters in it and an initial capacity specified by the capacity Note: An instance of a StringBuilder is a mutable sequence of characters. The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point. Incorrect answers: StringBuilder sb = new String("128"); StringBuilder not String is required. setCapacity or getInstance do not work.

Topics

#StringBuilder#constructors#capacity#Java API

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice