What are the different types of constructor in StringBuilder class

0 votes
Please explain me the different types of constructors used in a StringBuilder Class? Can someone explain them with an example?
Mar 5, 2019 in Java by Shyaam
472 views

2 answers to this question.

0 votes

There are different types of StringBuilder constructor in Java, they are as follows:

  • StringBuilder(): This constructs a string builder with no characters in it and has an initial capacity of 16 characters.
    StringBuilder str = new StringBuilder();
  • StringBuilder(int capacity): Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
    StringBuilder str = new StringBuilder(10);
  • StringBuilder(CharSequence seq): Constructs a string builder that contains the same characters as the specified CharSequence.
    StringBuilder str1 = new StringBuilder("AAABBCCCDDEE");
  • StringBuilder(String str): Constructs a string builder initialized to the contents of the specified string.
    StringBuilder str = new StringBuilder(str1);
    
These are the constructors. Hope this helps.
answered Mar 6, 2019 by Mariyam
0 votes
StringBuilder  we 4  as mentioned below.
answered Sep 1, 2020 by Sri
• 3,190 points

Related Questions In Java

0 votes
1 answer

What are the different methods of session management in servlets?

Session is a conversational state between client ...READ MORE

answered Feb 18, 2019 in Java by Frankie
• 9,830 points
10,901 views
+1 vote
1 answer

What are the types of memory in JVM?

The different types of Memory in JVM ...READ MORE

answered Mar 7, 2019 in Java by Priyaj
• 58,080 points
1,813 views
0 votes
1 answer

What are the different types of database testing?

The 3 types of Database Testing are Structural ...READ MORE

answered May 9, 2019 in Java by Frankie
• 9,830 points
1,080 views
0 votes
1 answer

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

answered May 11, 2018 in Java by Rishabh
• 3,620 points
695 views
+1 vote
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,620 points
458 views
+1 vote
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
465 views
+1 vote
1 answer

Performance difference of if/else vs switch statement in Java

The thing you are worried about is ...READ MORE

answered Jul 26, 2018 in Java by geek.erkami
• 2,680 points
2,097 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
2,359 views
0 votes
1 answer

What are the different ways of comparing Strings in Java?

The different ways of comparing string in ...READ MORE

answered Mar 5, 2019 in Java by Wasim
367 views
0 votes
1 answer

How to get rid of TLE in Java?

The TLE (Time limit exceed) problem occurs ...READ MORE

answered Mar 5, 2019 in Java by Disha
1,288 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP