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

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 3 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
(ii) String and String Buffer Class  difference between String and String Buffer Class
(ii) String and String Buffer Class
String and String Buffer Class  differences 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 
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
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 
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
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
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 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
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
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 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 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
PLEASE HELP WITH MY JAVA
PLEASE HELP WITH MY JAVA  Hey my name is Gavin and im a student at school that takes IT. my teacher has gave me a problem and i can't figure it out please help!!!!!!!! it is a for-loop question: Display the first 5 multiples
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 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
Retrieve the dynamic capacity of a list
in it using the size() method. Here is the Code of the Example : VecSize.java... Retrieve the dynamic capacity of a list        In this section you will learn to get the capacity
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 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
ShortBuffer in java, Use of remaining() method in short buffer.
ShortBuffer in java, Use of remaining() method in short buffer. In this tutorial, we will see how to use of remaining() method in short buffer. ShortBuffer...; The allocate(..)method allocate a new short buffer.  ShortBuffer
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
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
How to get the capacity of ByteBuffer in java.
; In this example, we will compute the capacity of buffer. The capacity() method returns the capacity of buffer. The method allocate( int capacity) creates..., we will discuss how to get the capacity of buffer. The ByteBuffer class
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      
ShortBuffer in java, Clean a short buffer by using clear method.
Clean a short buffer by using clear method. In this tutorial, we will discuss how to clean a short buffer by using clear method. ShortBuffer API... static ShortBuffer allocate( int capacity) The allocate(..) method
Please tell me the code to generate the below structure
Please tell me the code to generate the below structure  1 2 3 4 5 6 7 8 9 1 2 3 4 6 7 8 9 1 2 3 7 8 9 1 2 8 9 1 9 1 2 8 9 1 2 3 7 8 9 1 2 3 4 6 7 8 9 1 2 3
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()      
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 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
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok button. 6 Textbox to Add the 6 Team Name. Each Team Name In String(Like- A,B,C,D,E,F... Play Second Match With Same Team Then Generate The Error... EXAMPLE: A Team Play
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
Average Age of my Class?
Average Age of my Class?  average age of my class
Advertisements
 

 

 

DMCA.com