please clarify regarding capacity method of my below string buffer class example

Ads
 

please clarify regarding capacity method of my below string buffer class example

hi

here is the program below:

> import java.lang.*; public class
> Compare{ public static void
> main(String[] args) {
> System.out.println("StringBuffer
> insert and append example!");
> StringBuffer sb = new StringBuffer(0);
> //First position
> System.out.println(sb.insert(0,
> "vinoda")); int len = sb.length();
> System.out.println("length
> is"+sb.length());
> System.out.println("capacity
> is"+sb.capacity()); //last position
> System.out.println(sb.insert(len,
> "Deepak"));
> System.out.println("capacity
> is"+sb.capacity()); //Six position
> System.out.println(sb.insert(6,
> "Raj")); System.out.println("length
> is"+sb.length());
> System.out.println("capacity
> is"+sb.capacity()); //Always last
> System.out.println(sb.append("Mohit"));
> System.out.println(sb.append("raju"));
> System.out.println("length
> is"+sb.length());
> System.out.println("capacity
> is"+sb.capacity()); } }

o/p:

StringBuffer insert and append example!
vinoda
length is6
capacity is6
vinodaDeepak
capacity is14
vinodaRajDeepak
length is15
capacity is30
vinodaRajDeepakMohit
vinodaRajDeepakMohitraju
length is24
capacity is30

my question is how the capacity of s.buffer changed from 6 to 14 and to 30 and why it remained in 30 for the last operation.
thanks in advance

View Answers

Ads









Related Tutorials/Questions & Answers:
please clarify regarding capacity method of my below string buffer class example
please clarify regarding capacity method of my below string buffer class... class > Compare{ public static void > main(String[] args) { >...: StringBuffer insert and append example! vinoda length is6 capacity is6
Please clarify my doubt
Please clarify my doubt  /here is my sample code for deadlock/ class... A.last()"); } } class B { synchronized void bar(A a) { String...[] args) { new Deadlock(); } } My question is that class A has 2
Advertisements
(ii) String and String Buffer Class
String and String Buffer Class  differences between : String and String Buffer Class
(ii) String and String Buffer Class
(ii) String and String Buffer Class  difference between String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  difference between String and String Buffer Class... whereas String buffer objects are not constants but growable
Java bigdecimal toString example
;    Example below demonstrates working of bigdecimal class toString method. Method return type is string therefore method returns string value only. This bigdecimal class toString method generates, string representation
Java bigdecimal toPlainString example
;    Example below demonstrates working of bigdecimal class toPlainString method. Method return type is string therefore method returns string value only. This bigdecimal class toPlainString method generates, string
Example for a method in java which returns a class
Example for a method in java which returns a class  Hi, I want to create a 1 class,and declare some methods there.I need to method must returns a classname.when i call that particular method(which returns a class),how can i
Java bigdecimal negate method example
Java bigdecimal negate method example       Example below demonstrates working of bigdecimal class negate method. Method returns the same copy of the bigdecimal value
Java bigdecimal multiply method example
Java bigdecimal multiply method example       Example below demonstrates bigdecimal class multiply method example. Method returns a bigdecimal object value. Method
Get Class Name
; In the example given below we will learn how to get name of the particular class with package name. getName() method returns fully qualified name of the particular class in string format.       Here is the code
Java bigdecimal subtract method example
Java bigdecimal subtract method example       Example below demonstrates working of bigdecimal class subtract method. Method returns bigdecimal object values as per context
String equalsIgnoreCase(String Str)
explanation about the equalsIgnoreCase(String Str) method of String class. We are going to use equalsIgnoreCase(String Str) method of String... of the method. Description of the code: As shown in the example below we have taken
String intern()
the intern() method of String class. We are going to use intern() method of String class in Java. The description of the code is given below for the usage of the method. Description of the code: As shown in the example we have created
String indexOf() Method
the indexOf() method of String class. We are going to use indexOf() method of String class in Java. The description of the code is given below for the usage... String indexOf() Method      
String indexOf() method in Java
() method in java. indexOf() method which is of string class,  used to locate a character or string.  The String class provide two method... given below : public class IndexOf { public static void main(String args
String Determining a Character's Unicode Block
explanation about the UnicodeBlock() method of String class. We are going to use UnicodeBlock() method of String class in Java. The description of the code is given below for the usage of the method. Description of the code: As shown
String Concat()
() method of String class. We are going to use Concat() method of String class in Java. The description of the code is given below for the usage of the method... String Concat()      
explain the difference between string builder and string buffer classes
explain the difference between string builder and string buffer classes  Hi, Here is my code public static void main(String[] args) { String s1...; StringBuffer s4 = new StringBuffer(s1); } in this example how many objects are created
Java bigdecimal plus method example
Java bigdecimal plus method example       Example below demonstrates working of bigdecimal class plus method. Method always returns a bigdecimal value of positive nature as per
Java method Overriding
Below example illustrates method Overriding in java. Method overriding in java means a subclass method overriding a super class method. Superclass... class. In the example class B is is the sub class and class A is the super class
Regarding method returns multiple values
Regarding method returns multiple values  Hi, 1)I have a requirement like,1 method returns multiple values.how to do that one. 2)can i use method, for example like getFile()[] in this way or not. plzzzzzzzzzzzzzzzzzz provide
String getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
the getChars() method of String class. We are going to use getChars() method of String class in Java. The description of the code is given below for the usage of the method. Description of the code: As shown in the example we have taken
String replaceFirst() Method
. We are going to use replaceFirst() method of String class in Java. The description of the code is given below for the usage of the method. Description... String replaceFirst() Method     
Java bigdecimal signum example
;    Example below demonstrates working of bigdecimal class.... This bigdecimal class signum method generates, sign of the bigdecimal object value. After..., 0, +1.  For example if the bigdecimal value is negative,  method
regarding css file in my eclipse
regarding css file in my eclipse  hai frns i want a small help frm u.when ever i use css file in html or normal web browsers the output is coming... the output is not changing can anyone please tell me a solution regarding
Java bigdecimal multiply example
Java bigdecimal multiply example       Example below demonstrates bigdecimal class multiply method example. Method returns a bigdecimal object value. Method multiply 
Java bigdecimal toBigIntegerExact example
;     Example below demonstrates working of bigdecimal class toBigInteger  method. Method default return type is a biginteger class object value.  If the bigdecimal object value is 423.0, method
Java bigdecimal toBigInteger example
Java bigdecimal toBigInteger example       Example below demonstrates working of bigdecimal class toBigInteger  method. Method default return type is a biginteger
Java bigdecimal movePointLeft example
;    Example below demonstrates bigdecimal class movePointLeft method example. Method returns a bigdecimal object value. Method moves... inside the parentheses of the method.  In the example two bigdecimal
Java BigDecimal movePointRight example
;    Example below demonstrates bigdecimal class movePointRight method example. Method returns a bigdecimal object value. Method moves... passed inside the parentheses of the method. In the example one bigdecimal 

Ads