public final class FixedWidthStringBuffer
extends java.lang.Object
If you look into the mechanics of the java.lang.String and java.lang.StringBuffer class, you will understand why it is better to create a new one of these each time you need it as opposed to performing a StringBuffer.setLength (0), which forces re-allocation of the char[].
FixedWidthStringBuffer buf = new FixedWidthStringBuffer (100); buf.append (lastName, 25); buf.append (firstName, 25); System.out.println (buf.toString ()); buf = new FixedWidthStringBuffer (100); ...
String
,
StringBuffer
Constructor and Description |
---|
FixedWidthStringBuffer()
Create a new FixedWidthStringBuffer with
an initial size of 64 characters.
|
FixedWidthStringBuffer(int initialSize)
Create a new FixedWidthStringBuffer with
an initial size of 64 characters.
|
Modifier and Type | Method and Description |
---|---|
void |
append(char ch)
Several accessor methods which delegate directly
to the StringBuffer.
|
void |
append(java.lang.String s)
Several accessor methods which delegate directly
to the StringBuffer.
|
void |
append(java.lang.String s,
int width)
Append the given String to the buffer,
ensuring it occupies the given width.
|
char |
charAt(int pos)
Several accessor methods which delegate directly
to the StringBuffer.
|
java.lang.StringBuffer |
getStringBuffer()
Retrive the underlying StringBuffer.
|
int |
length()
Several accessor methods which delegate directly
to the StringBuffer.
|
void |
setCharAt(int pos,
char ch)
Set the character at the specified position to ch.
|
java.lang.String |
toString()
Return the string from the buffer.
|
public FixedWidthStringBuffer()
public FixedWidthStringBuffer(int initialSize)
initialSize
- The initial size of the underlying StringBuffer.public void append(java.lang.String s, int width)
s
- The String to append.width
- The field width.public java.lang.StringBuffer getStringBuffer()
public void append(java.lang.String s)
s
- the string to append.public void append(char ch)
ch
- the char to append.public int length()
public char charAt(int pos)
pos
- public void setCharAt(int pos, char ch)
pos
- The position in the buffer at which to place the character.ch
- The character to place in the buffer.public java.lang.String toString()
toString
in class java.lang.Object
String
,
StringBuffer
Copyright ? 2002 Clarity Systems Group, LLC. All Rights Reserved.