PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

StringBuilder in Java

← All stacks

Theory

80/270

StringBuilder in Java

StringBuilder is a mutable text builder for one thread. append, insert, reverse. Not synchronized, so faster than StringBuffer. This is the default builder in fresher code.

new StringBuilder().append("Ja").append("va").toString() → "Java". Reverse a string with new StringBuilder(s).reverse().toString().

String itself stays immutable. Builder is only for when you change text many times.

Let's take this on the board with one tiny Main class — no extra files. StringBuilder in Java — output: Hi Java. append changes the same StringBuilder — not a new String each time. Start from main, go line by line, and stop at each print. That output is the proof for StringBuilder.

Exam tip

Default mutable builder. Show append or reverse(). Contrast Buffer = synced.

Example

// StringBuilder demo
public class Main {
  public static void main(String[] args) {
    StringBuilder sb = new StringBuilder("Hi");
    sb.append(" Java");
    System.out.println(sb.toString());
  }
}

StringBuilder in Java — output: Hi Java. append changes the same StringBuilder — not a new String each time.

Short notes

  • DefStringBuilder = mutable text for one thread. Faster, not synchronized.
  • Ruleappend / reverse / toString. Default pick vs StringBuffer.
  • UseBuild text in a loop. Reverse a string.
  • RememberString stays immutable. Builder is the workbench.

Questions

1

StringBuilder vs StringBuffer?

2

How do you reverse a string?

Previous← StringBuffer in JavaNextDifference between String and StringBuffer →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.