Category Archives: Uncategorized

Java StringBuffer Example

As like String functionalities, StringBuffer method works much like string functionalities.  StringBuffer defined by growable and writable character sequences while it will represent the as constant length and unchangeable sequence of characters.

Here characters and substrings inserted in the middle of the statement or appended to the end of the statement. StringBuffer grows to make space for the kind of inclusion.

Java StringBuffer SubString EndParamenter Method

Java StringBuffer SubStringEndParameters Example | Java String Buffer

Java StringBuffer SubString  Method

Java StringBuffer SubString Example program – Java StringBuffer

Java StringBuffer Reverse Method

Java StringBuffer Reverse Method Example – Java StringBuffer

Java StringBuffer Replace Method

Java StringBufferReplace Method Example | Java StringBuffer

Java StringBuffer Length Method

Java StringBufferLength Method Example | Java StringBuffer

Java StringBuffer LastIndexOf Method

Java StringBuffer LastIndexOf Method Example | Java StringBuffer

Java StringBuffer Indexof Method

Java StringBuffer IndexOf Method Example | Java StringBuffer

Java StringBuffer DeleteCharAt Method

Java StringBufferDeleteCharAt Method Example | Java StringBuffer

Java StringBuffer Delete Method

Java StringBuffer Delete Method Example | Java StringBuffer

Java StringBuffer CharAt Method

Java StringBuffer charAt Method Example – Java StringBuffer

Java StringBuffer Append Method

Java StringBuffer Append Example -StringBuffer in Java

 

StringBuilder method has emerged even  Java has powerful string handling capabilities. The hidden story behind this StringBuffer method not synchronized, getting point was it is not thread-safe.

 

Java StringBuffer SubStringEndParameters Example | Java String Buffer

Following StringBuffer SubStringEndParameters ExampleReturns the Substring from the Main string between the specified index position values. Here the start index position value is inclusive and ends index position value is exclusive.

StringBufferSubStringEndParameters.java

import java.lang.StringBuffer;
public class StringBufferSubStringEndParameters {
 public static void main(String[] args) {

  StringBuffer s = new StringBuffer("Java Development Kit");
  System.out.println(s);

  System.out.println(s.substring(0, 12));

 }
}

Output:

Java Development Kit
Java Develop

Java StringBuffer SubString Example program – Java StringBuffer

Following StringBuffer SubString example program will Returns the Substring from the Main string based on the specified index position.

StringBufferSubString.java

import java.lang.StringBuffer;
public class StringBufferSubString {
 public static void main(String[] args) {

  StringBuffer b = new StringBuffer("Sun MicroSystems");
  System.out.println(b);

  System.out.println(b.substring(4));

 }
}

Output:

Sun MicroSystems
MicroSystems

Java StringBuffer Reverse Method Example – Java StringBuffer

Java has an inbuilt method called StringBuffer Reverse that will Reverses the given String. Following StringBuffer Reverse example program will return the reversed string from the given input string.

 StringBufferReverse.java

import java.lang.StringBuffer;
public class StringBufferReverse {
 public static void main(String[] args) {

  StringBuffer s = new StringBuffer("Java");
  System.out.println(s);
  System.out.println(s.reverse());


 }
}

Output:

Java
avaJ

Java StringBufferReplace Method Example | Java StringBuffer

Here java StringBuffer Replace method will Replace the old characters in the string with the specified characters at the specified index position values. It starts with index position value is inclusive and ends with index position value is exclusive.

StringBufferReplace.java

import java.lang.StringBuffer;
public class StringBufferReplace {
 public static void main(String[] args) {

  StringBuffer a = new StringBuffer("Welcome to Java");
  System.out.println(a);

  System.out.println(a.replace(11, 15, "Candid Java"));

 }
}

Output

Welcome to Java
Welcome to Candid Java

Java StringBufferLength Method Example | Java StringBuffer

Following StringBufferLength method will return the Length of the String which means the number of characters including Blank Space in the string.StringBuffer Length method has been implemented from Char Sequence interface.

StringBufferLength.java

import java.lang.StringBuffer;
public class StringBufferLength {
 public static void main(String[] args) {

  StringBuffer s = new StringBuffer("String Buffer");
  System.out.println(s);

  int a = s.length();
  System.out.println(a);
 }
}

Output:

String Buffer
13

Java StringBuffer LastIndexOf Method Example | Java StringBuffer

StringBufferLastIndexOf returns the index position of the Last Occurrence of the specified char in the String. Following program will return type is an integer.

StringBufferLastIndexOf.java


import java.lang.StringBuffer;
public class StringBufferLastIndexOf {
 public static void main(String[] args) {

  StringBuffer a = new StringBuffer("Full Stack Developer");
  int b = a.lastIndexOf("l");
  System.out.println(b);

  int c = a.lastIndexOf("e");
  System.out.println(c);

 }
}

Output

15
18

Java StringBuffer IndexOf Method Example | Java StringBuffer

StringBufferIndexOf example program will return the index position of First Occurrence of the specified char in the string. The following program will return type is an integer.

StringBufferIndexOf.java

import java.lang.StringBuffer;
public class StringBufferIndexOf {
 public static void main(String[] args) {

  StringBuffer a = new StringBuffer("Core Java and Advanced Java");
  int b = a.indexOf("Java");
  System.out.println(b);

  int c = a.indexOf("a");
  System.out.println(c);

 }
}

OutPut

5
6

Java StringBufferDeleteCharAt Method Example | Java StringBuffer

Following Java StringBuffer DeleteCharAt method will remove the char at the specified index from the string.

StringBufferDeleteCharAt.java

import java.lang.StringBuffer;
public class StringBufferDeleteCharAt {
 public static void main(String[] args) {

  StringBuffer s = new StringBuffer("Welcome To Java Programs");
  System.out.println(s);

  System.out.println(s.deleteCharAt(23));

  System.out.println(s.deleteCharAt(6));
 }
}

Output:

Welcome To Java Programs
Welcome To Java Program
Welcom To Java Program

Java StringBuffer Delete Method Example | Java StringBuffer

StringBuffer delete method removes the characters in the String between the specified start index and end index position values. Here the start index position value is inclusive and ends index position value is exclusive.

import java.lang.StringBuffer;
public class StringBufferDelete {
 public static void main(String[] args) {

  StringBuffer a = new StringBuffer("CoreJava");
  System.out.println(a);
  System.out.println(a.delete(0, 4));

 }
}

Output:

CoreJava
Java