The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Tutorial : Java StringBuilder Introduction

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ram N

Posts: 2777
Nickname: ramram
Registered: Jul, 2014

Ram N is Java Programmer
Java Tutorial : Java StringBuilder Introduction Posted: Apr 26, 2016 7:45 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Ram N.
Original Post: Java Tutorial : Java StringBuilder Introduction
Feed Title: JAVA EE
Feed URL: http://ramj2ee.blogspot.com/feeds/posts/default?alt=rss
Feed Description: This blog has viedo tutorials and Sample codes related to below Technologies. 1.J2EE 2.Java 3.Spring 4.Hibernate 5.Database 6.Oracle 7.Mysql 8.Design Patterns
Latest Java Buzz Posts
Latest Java Buzz Posts by Ram N
Latest Posts From JAVA EE

Advertisement

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

Click the below Image to Enlarge
Java Tutorial : Java StringBuilder Introduction 
Java Tutorial : Java StringBuilder Introduction 
Java Tutorial : Java StringBuilder Introduction 

StringBuilderDemo.java
public class StringBuilderDemo
{

public static void main(String[] args)
{
/*
* Constructs a string Builder with no characters in
* it and an initial capacity of 16 characters.
*/

StringBuilder sb1 = new StringBuilder();
System.out.println("sb1 = " + sb1);
System.out.println("sb1 capacity = " + sb1.capacity());

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

/*
* Constructs a string Builder with no characters in
* it and the specified initial capacity.
*/

StringBuilder sb2 = new StringBuilder(50);
System.out.println("sb2 = " + sb2);
System.out.println("sb2 capacity = " + sb2.capacity());

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

/*
* Constructs a string Builder initialized to the
* contents of the specified string. The initial
* capacity of the string Builder is 16 plus the
* length of the string argument.
*/

String str = "Hello";
StringBuilder sb3 = new StringBuilder(str);
System.out.println("sb3 = " + sb3);
System.out.println("sb3 capacity = " + sb3.capacity());

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

/*
* Constructs a string Builder that contains the same
* characters as the specified CharSequence. The
* initial capacity of the string Builder is 16 plus
* the length of the CharSequence argument.
*/

CharSequence charSequence = new StringBuilder("Welcome");
StringBuilder sb4 = new StringBuilder(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/StringBuilder.html
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringBuilderDemo_Intro_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/ea6705eb8d861d880326570ef3992b3db7646c7d/BasicJava/StringBuilderDemo_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
  • Read: Java Tutorial : Java StringBuilder Introduction

    Topic: 3 different ways to print exception message in java Previous Topic   Next Topic Topic: throw keyword in java with example

    Sponsored Links



    Google
      Web Artima.com   

    Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use