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 in Java by Shyaam
46 views

1 answer 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 5 by Mariyam

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 17 in Java by Frankie
• 9,810 points
760 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 in Java by Priyaj
• 56,900 points
308 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 in Java by Frankie
• 9,810 points
54 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,540 points
169 views
0 votes
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,540 points
65 views
0 votes
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,280 points
52 views
0 votes
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,320 points
465 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,190 points
429 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 in Java by Wasim
52 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 in Java by Disha
192 views