|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectxv.text.StringMaker
public class StringMaker
A very simple class for creating strings. This class is somewhat
lighter-weight than StringBuffer
at the expense of being much,
much less powerful. But if all you're doing is appending characters (or
arrays of characters) this class is much simpler than StringBuffer
.
It's also not thread-safe.
The main purpose for this class is that it allows you to reuse the existing
backing array indefinitely. clear()
does not actually clear the
buffer, it simply resets the offset to 0.
As of present, this class is slightly more efficient than
StringBuilder
in similar use cases.
All returned strings contain newly allocated char
arrays and never
share with the internal char
array.
Constructor Summary | |
---|---|
StringMaker()
|
|
StringMaker(int initialSize)
|
Method Summary | |
---|---|
Appendable |
append(char c)
Appends the given character. |
void |
append(char[] buf)
Appends the given character array. |
void |
append(char[] buf,
int offset,
int length)
Appends the given section of the given character array. |
Appendable |
append(CharSequence csq)
|
Appendable |
append(CharSequence csq,
int start,
int end)
|
void |
append(int c)
Appends a code point. |
void |
append(String s)
|
void |
append(String s,
int offset,
int length)
Appends the given section of the given string. |
char |
charAt(int index)
|
void |
clear()
"Clears" the string by resetting the string offset to 0. |
int |
length()
Gets the number of characters currently contained within this string maker. |
void |
setLength(int length)
Sets the length of the string. |
CharSequence |
subSequence(int start,
int end)
|
String |
toString()
Returns the contents of the string maker as a string. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public StringMaker()
public StringMaker(int initialSize)
Method Detail |
---|
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public void append(int c)
char
.
c
- the code point to appendpublic Appendable append(char c)
append
in interface Appendable
c
- the character to append
Appendable
public Appendable append(CharSequence csq, int start, int end)
append
in interface Appendable
public Appendable append(CharSequence csq)
append
in interface Appendable
public void append(char[] buf)
buf
- the array of characters to append
NullPointerException
- if buf
is null
public void append(char[] buf, int offset, int length)
buf
- the array of characters to appendoffset
- the offset into the array of characters to start appending
fromlength
- the number of characters to append
IndexOutOfBoundsException
- if offset
is less than 0, offset + length
is
greater than buf.length
, or length
is less
than 0
NullPointerException
- if buf
is null
public void append(String s)
public void append(String s, int offset, int length)
s
- the string to appendoffset
- the offset into the string to start appending fromlength
- the number of characters to append
IndexOutOfBoundsException
- if offset
is less than 0, offset + length
is
greater than s.length()
, or length
is less
than 0public void clear()
public int length()
toString().length()
would
return without the need to allocate a new string.
length
in interface CharSequence
public void setLength(int length)
StringBuilder.setLength(int)
).
length
- the new length
IndexOutOfBoundsException
- if the new length is less than 0.public String toString()
toString
in interface CharSequence
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |