Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners please clarify regarding capacity method of my below string buffer class example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


N.SENDIL KUMAR
please clarify regarding capacity method of my below string buffer class example
0 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

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
Get the limit position and capacity of a double type buffer.
Get the limit position and capacity of a character buffer. In this tutorial you will see how to get the limit position and capacity of a character buffer. The given example illustrate the use of limit() method which returns the buffer
Get the capacity of a buffer
Get the capacity of a buffer In this tutorial we will see how to get size of buffer using capacity() method. Code...;{   public static void main(String[] args) 
Get the capacity of a double type buffer
Get the capacity of a double buffer In this tutorial we will see how to get size of a double buffer using capacity() method. Code...;DoubleBufferDemo {   public static void main(String[] args
Get the limit position and capacity of a character buffer.
Get the limit position and capacity of a character buffer. In this tutorial you will see how to get the limit position and capacity of a character buffer. The given example illustrate the use of limit() method which returns the buffer
Clarify my doubt - JSP-Servlet
Clarify my doubt  Hi All, Although i know the concept of Servlet & JSP, but I have never got a chance to work in EJB . So could u please tell me how to create web Project in netbeans and deploy it in tomcat AND/OR creating a web
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back... the matching tutors to the parent. I was telling you that my degree... and the locations for example, there will be a table that display the following
clarify date class - Java Beginners
clarify date class  Dear, clarify this question... "Develop Date class in Java similar to the one available in java.util package. Use JavaDoc... in java.util or any packages.. please. thanks in advance. regards S.v.Doss
Create a float buffer by using wrap method of FloatBuffer class.
Create a float buffer by using wrap method of FloatBuffer class. In this tutorial, we will see how to create a float buffer by using wrap method...[] array)  The wrap() method create a float buffer by wrapping 
Create a short buffer by using wrap method of ShortBuffer class.
Create a short buffer by using wrap method of ShortBuffer class. In this tutorial, we will see how to create a shortt buffer by using wrap method...[] array)  The wrap() method create a short buffer by wrapping 
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... expert's advise. Many thanks.   Hi Friend, Please clarify your... did not specify my question too clearly. Here's my 2 database
JDOM CDATA Example, Use of append(String str) method of CDATA class.
JDOM CDATA Example, Use of append(String str) method of CDATA class. In this tutorial, we will implement append() method of  CDATA class... with a string. The setContent(Content content ) method of Element class is used to set
Use of hasRemaining() method in float buffer class.
Use of hasRemaining() method in float buffer class. In this tutorial, we will see the use of  hasRemaining method of Buffer class in FloatBuffer...; The allocate(..)method allocate a new float buffer. final boolean
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
Use of isDirect() method of byte buffer class in java.
capacity)  The allocate() method allocate a byte buffer...Use of isDirect() method of ByteBuffer class in java. In this tutorial... isDirect() The isDirect() method tells whether this associated buffer
String indexOf method example
.style1 { font-size: medium; } String indexOf() method example:- String class method indexOf() is use to find the starting character position of the substring from the string. The indexOf() method start to search from
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
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
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
How to clean a buffer using clear method in java.
;    In this example, the clear() method clean a buffer for further... will be capacity of buffer. The method allocate ( int capacity) creates a new byte...() method create a byte buffer of specified capacity.  code
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
Regarding My 3rd Question in Java - Swing AWT
in below these our data will appear so my question that is there any method...Regarding My 3rd Question in Java  sir in Netbeans By default JTable... to display like this below one Title Database Data RollNO
String substring method example
.style1 { font-size: medium; } String substring() method example... a string. String class provide methods for finding substring from string. Method... string. In this example we have used this method. Example:- <?xml
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
Java string buffer
Java string buffer  what is stringBuffer and StringBuilder
Java string buffer
Java string buffer  What is the basic difference between string and stringbuffer object
 

 

 

DMCA.com