How to Get SubString of StringBuffer in Java


This example will use substring method of java StringBuffer class to get a substring of content of the StringBuffer.

Source Code

package com.beginner.examples;

public class JavaStringBufferSubString {

	public static void main(String[] args) {
		
		//create StringBuffer.
		StringBuffer stringBuffer = new StringBuffer("Hello World !");
		
		/*
		 * Use substring(int start) method to get the substring.
		 */
		String stringPart = stringBuffer.substring(6);
		
		System.out.println(stringPart);
	}

}

Output:

World !
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments