Java StringBuffer substring Example
StringBuffer class substring method example. This example shows you how to use substring method.
StringBuffer class substring method example. This example shows you how to use substring method.subString method returns a new String that contains a subsequence of characters currently contained in this character sequence. The substring begins at the specified index and extends to the end of this sequence.
Here is the code
/**
* @(#) Substring. java
* A class representing substring method
* @Version 01-May-2008
* @author Rose India Team
*/
public class Substring{
public static void main(String[] args){
// Construct a StringBuffer object:
StringBuffer s = new StringBuffer("Hello world!");
// substring starting at the 6th characte:
System.out.println("In \"" + s +"\", substring is: "+ s.substring(6));
// the substring starting from 6th character up to, but not including, the 11th character:
System.out.println("Substring is: "+ s.substring(6,11));
}
} |
-
|