Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
502 views
in JECRC University B.Tech(CSE-V Sem) Java Programming Lab by Goeduhub's Expert (5.8k points)

To write a java program to create a StringBuffer object and illustrate how to append characters and to display the capacity and length of the string buffer 

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (5.8k points)
edited by
 
Best answer

Program Code

import java.util.*;

public class Demo

{

  public static void main(String[] args)

  {

    StringBuffer sb=new StringBuffer("Welcome to goeduhub");

    System.out.println(sb);

    System.out.println("Initial capacity: "+sb.capacity());

    sb.append(" Technologies ");

    System.out.println(sb);

    sb.append("p"); //appending characters

    sb.append("i");

    sb.append("n ");

    System.out.println(sb);

    sb.append("302012");

    System.out.println(sb);

    System.out.println("Length of StringBuffer object:  "+sb.length());

    System.out.println("Final capacity: "+sb.capacity());

   }

}

Output

Welcome to goeduhub

Initial capacity: 35

Welcome to goeduhub Technologies

Welcome to goeduhub Technologies pin

Welcome to goeduhub Technologies pin 302012

Length of StringBuffer object: 43

Final capacity: 72


For more JU V Sem Java Lab Experiments Click here


3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...