Friday, 1 April 2016

Java Tutorial : Java StringBuffer Introduction


Click here to watch in Youtube :
https://www.youtube.com/watch?v=aog8IHEK9BI&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java StringBuffer Introduction 
Java Tutorial : Java StringBuffer Introduction 
Java Tutorial : Java StringBuffer Introduction 
StringBufferDemo.java
public class StringBufferDemo
{

    public static void main(String[] args)
    {
        /*
         * Constructs a string buffer with no characters in
         * it and an initial capacity of 16 characters.
         */
        StringBuffer sb1 = new StringBuffer();
        System.out.println("sb1 = " + sb1);
        System.out.println("sb1 capacity = " + sb1.capacity());

        System.out.println("-----------------------");

        /*
         * Constructs a string buffer with no characters in
         * it and the specified initial capacity.
         */
        StringBuffer sb2 = new StringBuffer(50);
        System.out.println("sb2 = " + sb2);
        System.out.println("sb2 capacity = " + sb2.capacity());

        System.out.println("-----------------------");

        /*
         * Constructs a string buffer initialized to the
         * contents of the specified string. The initial
         * capacity of the string buffer is 16 plus the
         * length of the string argument.
         */
        String str = "Hello";
        StringBuffer sb3 = new StringBuffer(str);
        System.out.println("sb3 = " + sb3);
        System.out.println("sb3 capacity = " + sb3.capacity());

        System.out.println("-----------------------");

        /*
         * Constructs a string buffer that contains the same
         * characters as the specified CharSequence. The
         * initial capacity of the string buffer is 16 plus
         * the length of the CharSequence argument.
         */
        CharSequence charSequence = new StringBuffer("Welcome");
        StringBuffer sb4 = new StringBuffer(charSequence);
        System.out.println("sb4 = " + sb4);
        System.out.println("sb4 capacity = " + sb4.capacity());

    }
}
Output
sb1 = 
sb1 capacity = 16
-----------------------
sb2 = 
sb2 capacity = 50
-----------------------
sb3 = Hello
sb3 capacity = 21
-----------------------
sb4 = Welcome
sb4 capacity = 23
Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/StringBuffer.html

Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringBufferDemo_Intro_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringBufferDemo_Intro_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8be38147a030ff6efd24e1bdc0d15c0306083f5f/BasicJava/StringBufferDemo_Intro_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge