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

 
 


N.SENDIL KUMAR
please clarify regarding capacity method of my below string buffer class example
0 Answer(s)      2 years and a month 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

View Answers









Related Pages:
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
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 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
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) 
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
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
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
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
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
capacity of list - Java Interview Questions
capacity of list  How to find the capacity of list. is there any method to find capacity of list like vector.capacity(); Thanks   Hi... class ListCapacity{ public static void main(String args[]){ List list = new
(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
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
(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
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 
String Buffer insert and append example
String Buffer insert and append example   ... that has '0' capacity. This program inserts the data in the string buffer using... positions. But the append() method also add data in string buffer in ending position
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 
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
Regarding Login application program
----------------------- is there any problem Please send to my mail id(shivatwoshiva@gmail.com...Regarding Login application program  Hi this is shiva. iam writing.... in that, the values are not getting from the formbean.my formbean class name is "myform
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
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
How to create a int buffer with the help of byte buffer.
; The allocate() method allocate a byte buffer of given capacity. ...() The capacity() method returns the capacity of associated int buffer...() method returns int buffer based in byte buffer. Buffer API
How to create a long buffer with the help of byte buffer.
; The allocate() method allocate a byte buffer of given capacity. ...() The capacity() method returns the capacity of associated long buffer...() method returns  long buffer based in byte buffer. Buffer API
Creates a view of  byte buffer as a int buffer.
(..)method allocate a new byte buffer. abstract IntBuffer asIntBuffer() The asIntBuffer() method creates a view of byte buffer as a int buffer. int limit() The limit() method returns
Creates a view of  byte buffer as a long buffer.
; The allocate(..)method allocate a new byte buffer. abstract LongBuffer asLongBuffer() The asLongBuffer() method creates a view of byte buffer as a long buffer. int limit() The limit() method
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
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
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
clarify bt/w service() and doget/dopost()
String. It can send only limited amount of data. In doPost() method the user...clarify bt/w service() and doget/dopost()   Dear friends, i ve question regarding service()and doget/dopost.. the container calls service() where
How to create a short buffer with the help of byte buffer.
; The allocate() method allocate a byte buffer of given capacity. ...;short buffer. final int capacity() The capacity() method...() The asShortBuffer() method returns short buffer based on byte buffer
How to create a duplicate buffer of a long buffer in java.
; The allocate(..) method allocate a long buffer of given capacity... class. It provides the following methods: Return type Method...() method returns a duplicate buffer that share the content of available buffer
Creates a view of byte buffer as a char buffer.
; The allocate(...)method allocate a new byte buffer. abstract Charbuffer asCharBuffer() The asCharBuffer() method creates a view of byte buffer as a char buffer. int limit() The limit() method
Creates a view of this byte buffer as a double buffer.
; The allocate(...)method allocate a new byte buffer. abstract...() The limit() method returns the limit of associated buffer. int position() The position() method returns the position of associated buffer
Creates a view of  byte buffer as a float buffer.
; The allocate(..)method allocate a new byte buffer. abstract...() method returns the limit of associated buffer. int position() The position() method returns the position of associated buffer
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
Compare a float buffer with another float buffer.
(..)method allocate a new float buffer. int compareTo(FloatBuffer buffer) The compareTo() method returns 0, -1 or 1. It means...Compare a float buffer with another float buffer.  In this tutorial, we
Compare a int buffer with another int buffer.
static IntBuffer allocate(int capacity)  The allocate(..)method...) The compareTo() method returns 0, -1 or 1. It means this buffer is equal, less...Compare a int buffer with another int buffer.  In this tutorial, we
Display total disk drive capacity
This method gets the total disk capacity in the bytes. Code... of this example depends upon number of drive you have and the total disk capacity...Description: This example will demonstrate how to get the total disk space
Create a int buffer by wrapping an int array into a buffer.
() The capacity() method returns the capacity of associated int buffer... into a buffer. IntBuffer API: The java.nio.IntBuffer class extends java.nio.Buffer class. It provides the following methods: Return type Method
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      
Compare a long buffer with another long buffer.
(..)method allocate a new long buffer. int compareTo(LongBuffer buffer) The compareTo() method returns 0, -1 or 1. It means this buffer...Compare a long buffer with another long buffer.  In this tutorial, we
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
regarding sending mesage - JavaMail
regarding sending mesage  i have tried the following program... javax.activation.*; import javax.naming.*; public class SendMail { public static void main(String args[]) throws Exception { String host
Transfer the content of a int buffer into another int buffer.
int buffer. IntBufferAPI: The java.nio.IntBuffer class extends... Method Description static IntBuffer allocate(int capacity)  The allocate(..)method allocate a new int buffer
Transfer the content of a float buffer into another float buffer.
(int capacity)  The allocate(..)method allocate a new byte buffer.  FloatBuffer put(FloatBuffer buffer) The put(..)method... into another float buffer. FloatBufferAPI: The java.nio.FloatBuffer class
regarding applets - Java Beginners
regarding applets  sir can you please tell how one applet can send..., import java.awt.*; import java.awt.Dimension; public class GridCanvas extends Canvas { private final int NumLines = 10; private String greeting
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, Compare a short buffer with another short buffer.
(..) method allocate a short buffer of given capacity. int compareTo(ShortBuffer buffer) The compareTo(...) method returns 0...Compare a short buffer with another short buffer.  In this tutorial, we

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.