Java Topics
HubJava Collections FrameworkCollections Practice ProgramsComparable vs ComparatorGenericsIteratorArrayListLinkedListStackVectorHashMapHashtableLinkedHashMapTreeMapArrayDequeDeque Double-Ended QueuePriorityQueueHashSetLinkedHashSetTreeSetAdapter PatternBuilder PatternFactory PatternMVC PatternObserver PatternSingleton PatternDynamic ProgrammingGraphHashingHeapLinked List DSAQueue DSARecursionSearching AlgorithmsSorting AlgorithmsStack DSATime ComplexityTreesException Handling Best PracticesCustom ExceptionException Hierarchyfinally BlockException Handlingthrow aur throwstry-catchBuffered StreamsByte StreamsCharacter StreamsDeserializationFile ClassJava NIO New I/OSerializationArrays in JavaArray OperationsArray Practice ProgramsArray Interview QuestionsJagged ArrayMulti-Dimensional ArraysOne Dimensional Arraybreak aur continuedo-while Loopfor Loopif-else StatementsNested Loopsswitch-case Statementwhile LoopJava Compilation ProcessJava ki FeaturesPehla Java ProgramHistory of JavaJava EditionsJava Program StructureJDK, JRE aur JVMJava Kya Hai?Immutable StringsString Class in JavaString Interview QuestionsString MethodsString Practice ProgramsStringBufferStringBuilderComments in JavaData Types in JavaIdentifiers in JavaInput & Output in JavaJava KeywordsOperators in JavaType Casting in JavaVariables in JavaJava Coding Interview QuestionsCollections Interview QuestionsCore Java Interview QuestionsJDBC Interview QuestionsMultithreading Interview QuestionsOOPs Interview QuestionsSpring Framework Interview QuestionsJava 8 Date/Time APIDefault aur Static Methods in InterfaceFunctional InterfaceLambda ExpressionMethod ReferenceOptional ClassStream APIBatch ProcessingCallableStatementJDBC ArchitectureJDBC — Java Database ConnectivityJDBC Practice ProjectsMySQL ConnectionPreparedStatementResultSetStatement InterfaceTransaction ManagementCreating ThreadsDaemon ThreadExecutor FrameworkInter-Thread CommunicationMultithreading Practice ProgramsRunnable InterfaceSynchronizationThread ClassMultithreading IntroductionThread Life CycleThread PriorityJava Cheat SheetImportant Formulas & Key ConceptsImportant Java ProgramsJava Quick RevisionAbstract ClassAbstractionAnonymous ClassClass and ObjectConstructorEncapsulationInheritanceInner ClassInterfaceMethod OverloadingMethod OverridingObject ClassObject CloningObject-Oriented Programming OOPPolymorphismstatic Keywordsuper Keywordthis KeywordWrapper ClassesArray Practice ProgramsBasic Java Practice ProgramsCollection Practice ProgramsJDBC Practice ProgramsMultithreading Practice ProgramsOOPs Practice ProgramsPlacement Coding QuestionsString Practice ProgramsBanking SystemChat ApplicationE-Commerce Backend — Spring Boot REST APIEmployee Management SystemLibrary Management SystemSpring Boot Fullstack ProjectStudent Management SystemCookies in ServletExpression Language ELGenericServletHttpServletJavaServer Pages JSPJSP TagsMVC ArchitectureHttpServletRequest & HttpServletResponseServlet IntroductionServlet Life CycleSession TrackingDependency InjectionSpring BeansSpring CoreSpring FrameworkAPI GatewaySpring Cloud Config ServerDocker DeploymentEureka Server — Service DiscoverySpring Boot CRUD ApplicationException Handling in Spring BootJWT AuthenticationREST API in Spring BootSpring SecuritySpring BootSpring Data JPAValidation in Spring Boot
StringBuffer
Last Updated : 26 May, 2026
title: StringBuffer in Java
Fundamentals30 words3 headingsExamples included
title: StringBuffer in Java description: StringBuffer class — mutable aur thread-safe String
StringBuffer ek mutable sequence of characters hai. Thread-safe (synchronized) hai.
Create karna
java exampleWoHoTech
StringBuffer sb = new StringBuffer(); // empty
StringBuffer sb2 = new StringBuffer("Hello"); // with initial value
StringBuffer sb3 = new StringBuffer(50); // with capacityImportant Methods
java exampleWoHoTech
StringBuffer sb = new StringBuffer("Hello");
// Append
sb.append(" World"); // "Hello World"
sb.append(123); // "Hello World123"
// Insert
sb.insert(5, " Java"); // "Hello Java World123"
// Delete
sb.delete(5, 10); // "Hello World123" (5 to 9 delete)
// Replace
sb.replace(0, 5, "Hi"); // Replace 0-4 with "Hi"
// Reverse
sb.reverse(); // Reverse the content
// Length aur Capacity
sb.length() // Current length
sb.capacity() // Current capacity (default 16 + initial)
// charAt, setCharAt
sb.charAt(0) // Character at index
sb.setCharAt(0, 'h') // Set character
// toString
sb.toString() // Convert to String
// deleteCharAt
sb.deleteCharAt(0) // Delete first char
// indexOf
sb.indexOf("World") // Find substring indexExample
StringBuffer sb = new StringBuffer();
for (int i = 1; i <= 5; i++) {
sb.append(i);
if (i < 5) sb.append("-");
}
System.out.println(sb.toString()); // 1-2-3-4-5
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for StringBuffer.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Java topic.
Search Terms
java, java programming, core java, java master course, java notes, master, course, fundamentals
Related Java Topics
Continue learning this concept
FundamentalsImmutable Stringstitle: Immutable Strings in JavaFundamentalsString Class in Javatitle: String Class in JavaFundamentalsString Interview Questionstitle: String Interview QuestionsFundamentalsString Methodstitle: String MethodsFundamentalsString Practice Programstitle: String ProgramsFundamentalsStringBuildertitle: StringBuilder in Java