Description: The substring() method in Java StringBuffer returns a new StringBuffer object that contains a substring of the original StringBuffer. The method takes two arguments - the first argument is the starting index of the substring, and the second argument is the ending index of the substring (exclusive).
Code Examples:
Example 1: Get a substring from a StringBuffer starting at index 3 and ending at index 7.
StringBuffer sb = new StringBuffer("Hello World"); StringBuffer sub = sb.substring(3, 7); System.out.println(sub); // Output: "lo W"
Example 2: Get the first 5 characters of a StringBuffer.
StringBuffer sb = new StringBuffer("Hello World"); StringBuffer sub = sb.substring(0, 5); System.out.println(sub); // Output: "Hello"
Package Library: The StringBuffer substring() method is part of the java.lang package in Java.
Java StringBuffer.substring - 30 examples found. These are the top rated real world Java examples of StringBuffer.substring extracted from open source projects. You can rate examples to help us improve the quality of examples.