Example of String Buffer

Here we are writing a program which show that how can we create a string buffer and how use that.


package com.javaforecast4u;

public class ExampleStringBuffer {

    /**
     * @author:arbind
     */
    public static void main(String[] args) {
       StringBuffer b=new StringBuffer("Java Forecast 4u");
       System.out.println("buffer="+b);
       System.out.println("LENGTH="+b.length());
       System.out.println("CAPACITY="+b.capacity());
       String str=b.toString();
       System.out.println("str=" +str);
       System.out.println("LENGTH="+str.length());
       b.append(" "+str.substring(0,18)+"foolishness,");
       System.out.println("buffer="+b);
       System.out.println("LENGTH="+b.length());
       System.out.println("CAPACITY="+b.capacity());
       System.out.println("str="+str);
             } 

}

0 comments :

Post a Comment