java::lang::String Class Reference

Inheritance diagram for java::lang::String:

Inheritance graph
java::lang::Objectjava::lang::Interfacejava::lang::Comparable
[legend]
Collaboration diagram for java::lang::String:

Collaboration graph
java::lang::Objectjava::lang::Interfacejava::lang::ObjectRefjava::lang::Comparable
[legend]

List of all members.


Detailed Description

The String class represents character strings.

All string literals in Java programs, such as "abc", are implemented as instances of this class.

Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:

<blockquote>

     String str = "abc";
 
</blockquote>

is equivalent to:

<blockquote>

     char data[] = {'a', 'b', 'c'};
     String str = new String(data);
 
</blockquote>

Here are some more examples of how strings can be used:

<blockquote>

     System.out.println("abc");
     String cde = "cde";
     System.out.println("abc" + cde);
     String c = "abc".substring(2,3);
     String d = cde.substring(1, 2);
 
</blockquote>

The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.

The Java language provides special support for the string concatentation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuffer class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.

Author:
Lee Boynton

Arthur van Hoff

Version:
1.130, 02/09/01
Since:
JDK1.0

Public Member Functions

 String (const jbyte *=nilCString, jint ofs=0, jint size=-1)
 String (const Array< jbyte > &src, jint ofs=0, jint size=-1)
 Construct a new String by converting the specified array of bytes using the platform's default character encoding.
 String (const jchar *src, jint ofs=0, jint size=-1)
 Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.
 String (const Array< jchar > &src, jint ofs=0, jint size=-1)
 Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.
 String (const String &src)
 String (const Object &src)
 String (jboolean src)
 String (jbyte src)
 String (jchar src)
 String (jshort src)
 String (jint src, jint radix=10)
 String (juint src, jint radix=10)
 String (jlong src, jint radix=10)
 String (julong src, jint radix=10)
 String (jfloat src)
 String (jdouble src)
 String (jvoid src)
 String (jobject src)
Stringoperator= (const String &src)
Stringoperator+= (const String &src)
String operator+ (const String &src) const
virtual jboolean equals (const Object &src) const
 Compares this string to the specified object.
virtual jboolean equals (const String &src) const
virtual jboolean equals (const jbyte *src) const
 Compares this string to the specified C string.
virtual jboolean equals (const jchar *src) const
 Compares this string to the specified wide C string.
virtual jint hashCode () const
 Returns a hashcode for this string.
virtual String toString () const
 This object (which is already a string!) is itself returned.
virtual Array< jbytetoCString () const
 
Returns:
the Cstring in byte array.

virtual Array< jbytetoByteArray () const
 
Returns:
the string in byte array.

virtual Array< jchartoWCString () const
 
Returns:
the Wide Cstring in char array.

virtual Array< jchartoCharArray () const
 
Returns:
the string in char array.

jint toInt (jint radix=10) const
 
Returns:
Int.

jlong toLong (jint radix=10) const
 
Returns:
Long.

jfloat toFloat () const
 
Returns:
Float.

jdouble toDouble () const
 
Returns:
Double.

virtual jint length () const
 Returns the length of this string.
jchar charAt (jint index) const
 Returns the character at the specified index.
void getChars (jint srcBegin, jint srcEnd, Array< jchar > &dst, jint dstBegin) const
 Characters are copied from this string buffer into the destination character array dst.
jint compareTo (const Object &o) const
 Compares this String to another Object.
jint compareTo (const String &s) const
jboolean equalsIgnoreCase (const String &another) const
 Compares this String to another String, ignoring case considerations.
jint compareToIgnoreCase (const String &str) const
 Compares two strings lexicographically, ignoring case considerations.
jboolean regionMatches (jint toffset, const String &other, jint ooffset, jint len) const
 Tests if two string regions are equal.
jboolean regionMatchesIgnoreCase (jint toffset, const String &other, jint ooffset, jint len) const
 Tests if two string regions are equal.
jboolean startsWith (const String &prefix, jint toffset=0) const
 Tests if this string starts with the specified prefix beginning a specified index.
jboolean endsWith (const String &suffix) const
 Tests if this string ends with the specified suffix.
jint indexOf (jchar ch, jint fromIndex=0) const
 Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
jint lastIndexOf (jchar ch, jint fromIndex=-1) const
 Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.
jint indexOf (const String &str, jint fromIndex=0) const
 Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.
jint lastIndexOf (const String &str, jint fromIndex=-1) const
 Returns the index within this string of the last occurrence of the specified substring.
String substring (jint beginIndex, jint endIndex=-1) const
 Returns a new string that is a substring of this string.
String concat (const String &str) const
 Concatenates the specified string to the end of this string.
String replace (jchar oldChar, jchar newChar) const
 Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
String toLowerCase () const
 Converts all of the characters in this String to lower case using the rules of the default locale, which is returned by Locale.getDefault.
String toUpperCase () const
 Converts all of the characters in this String to upper case using the rules of the default locale, which is returned by Locale.getDefault.
String trim () const
 Removes white space from both ends of this string.
jint capacity () const
 Returns the current capacity of the String buffer.
void ensureCapacity (jint minimumCapacity)
 Ensures that the capacity of the buffer is at least equal to the specified minimum.
void setLength (jint newLength)
 Sets the length of this String buffer.
void setCharAt (jint index, jchar ch)
 The character at the specified index of this string buffer is set to ch.
Stringappend (const String &src)
 Appends the string to this string buffer.
Stringremove (jint start, jint end=-1)
 Removes the characters in a substring of this StringBuffer.
StringremoveCharAt (int index)
 Removes the character at the specified position in this StringBuffer (shortening the StringBuffer by one character).
Stringreplace (jint start, jint end, const String &str)
 Replaces the characters in a substring of this StringBuffer with characters in the specified String.
Stringinsert (jint offset, const String &str)
 Inserts the string into this string buffer.
Stringreverse ()
 The character sequence contained in this string buffer is replaced by the reverse of the sequence.

Constructor & Destructor Documentation

java::lang::String::String ( const jbyte = nilCString,
jint  ofs = 0,
jint  size = -1 
)

java::lang::String::String ( const Array< jbyte > &  src,
jint  ofs = 0,
jint  size = -1 
)

Construct a new String by converting the specified array of bytes using the platform's default character encoding.

The length of the new String is a function of the encoding, and hence may not be equal to the length of the byte array.

Parameters:
bytes The bytes to be converted into characters
Since:
JDK1.1

java::lang::String::String ( const jchar src,
jint  ofs = 0,
jint  size = -1 
)

Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.

The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string.

Parameters:
src the initial value of the string.
Exceptions:
NullPointerException if value is null.

java::lang::String::String ( const Array< jchar > &  src,
jint  ofs = 0,
jint  size = -1 
)

Allocates a new String so that it represents the sequence of characters currently contained in the character array argument.

The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string.

Parameters:
src the initial value of the string.
Exceptions:
NullPointerException if value is null.

java::lang::String::String ( const String src  ) 

java::lang::String::String ( const Object src  ) 

java::lang::String::String ( jboolean  src  ) 

java::lang::String::String ( jbyte  src  ) 

java::lang::String::String ( jchar  src  ) 

java::lang::String::String ( jshort  src  ) 

java::lang::String::String ( jint  src,
jint  radix = 10 
)

java::lang::String::String ( juint  src,
jint  radix = 10 
)

java::lang::String::String ( jlong  src,
jint  radix = 10 
)

java::lang::String::String ( julong  src,
jint  radix = 10 
)

java::lang::String::String ( jfloat  src  ) 

java::lang::String::String ( jdouble  src  ) 

java::lang::String::String ( jvoid  src  ) 

java::lang::String::String ( jobject  src  ) 


Member Function Documentation

String& java::lang::String::operator= ( const String src  ) 

String& java::lang::String::operator+= ( const String src  ) 

String java::lang::String::operator+ ( const String src  )  const

virtual jboolean java::lang::String::equals ( const Object src  )  const [virtual]

Compares this string to the specified object.

The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Parameters:
src the object to compare this String against.
Returns:
true if the String are equal; false otherwise.

Reimplemented from java::lang::Object.

virtual jboolean java::lang::String::equals ( const String src  )  const [virtual]

virtual jboolean java::lang::String::equals ( const jbyte src  )  const [virtual]

Compares this string to the specified C string.

The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Parameters:
src the C string to compare this String against.
Returns:
true if the String are equal; false otherwise.

virtual jboolean java::lang::String::equals ( const jchar src  )  const [virtual]

Compares this string to the specified wide C string.

The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

Parameters:
src the wide C string to compare this String against.
Returns:
true if the String are equal; false otherwise.

virtual jint java::lang::String::hashCode (  )  const [virtual]

Returns a hashcode for this string.

The hashcode for a String object is computed as <blockquote>

 
 s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
 
</blockquote> using int arithmetic, where s[i] is the ith character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)

Returns:
a hash code value for this object.

Reimplemented from java::lang::Object.

virtual String java::lang::String::toString (  )  const [inline, virtual]

This object (which is already a string!) is itself returned.

Returns:
the string itself.

Reimplemented from java::lang::Object.

virtual Array<jbyte> java::lang::String::toCString (  )  const [virtual]

Returns:
the Cstring in byte array.

virtual Array<jbyte> java::lang::String::toByteArray (  )  const [virtual]

Returns:
the string in byte array.

virtual Array<jchar> java::lang::String::toWCString (  )  const [virtual]

Returns:
the Wide Cstring in char array.

virtual Array<jchar> java::lang::String::toCharArray (  )  const [virtual]

Returns:
the string in char array.

jint java::lang::String::toInt ( jint  radix = 10  )  const

Returns:
Int.

jlong java::lang::String::toLong ( jint  radix = 10  )  const

Returns:
Long.

jfloat java::lang::String::toFloat (  )  const

Returns:
Float.

jdouble java::lang::String::toDouble (  )  const

Returns:
Double.

virtual jint java::lang::String::length (  )  const [virtual]

Returns the length of this string.

The length is equal to the number of 16-bit Unicode characters in the string.

Returns:
the length of the sequence of characters represented by this object.

jchar java::lang::String::charAt ( jint  index  )  const

Returns the character at the specified index.

An index ranges from 0 to length() - 1. The first character of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

Parameters:
index the index of the character.
Returns:
the character at the specified index of this string. The first character is at index 0.
Exceptions:
IndexOutOfBoundsException if the index argument is negative or not less than the length of this string.

void java::lang::String::getChars ( jint  srcBegin,
jint  srcEnd,
Array< jchar > &  dst,
jint  dstBegin 
) const

Characters are copied from this string buffer into the destination character array dst.

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

<blockquote>

 dstbegin + (srcEnd-srcBegin) - 1
 
</blockquote>

Parameters:
srcBegin start copying at this offset in the string buffer.
srcEnd stop copying at this offset in the string buffer.
dst the array to copy the data into.
dstBegin offset into dst.
Exceptions:
NullPointerException if dst is null.
IndexOutOfBoundsException if any of the following is true:
  • srcBegin is negative
  • dstBegin is negative
  • the srcBegin argument is greater than the srcEnd argument.
  • srcEnd is greater than this.length(), the current length of this string buffer.
  • dstBegin+srcEnd-srcBegin is greater than dst.length

jint java::lang::String::compareTo ( const Object o  )  const [virtual]

Compares this String to another Object.

If the Object is a String, this function behaves like compareTo(String). Otherwise, it throws a ClassCastException (as Strings are comparable only to other Strings).

Parameters:
o the Object to be compared.
Returns:
the value 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically greater than this string; and a value greater than 0 if the argument is a string lexicographically less than this string.
Exceptions:
<code>ClassCastException</code> if the argument is not a String.
See also:
JComparable
Since:
1.2

Reimplemented from java::lang::Comparable.

jint java::lang::String::compareTo ( const String s  )  const

jboolean java::lang::String::equalsIgnoreCase ( const String another  )  const

Compares this String to another String, ignoring case considerations.

Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case.

Two characters c1 and c2 are considered the same, ignoring case if at least one of the following is true:

Parameters:
anotherString the String to compare this String against.
Returns:
true if the argument is not null and the Strings are equal, ignoring case; false otherwise.

jint java::lang::String::compareToIgnoreCase ( const String str  )  const

Compares two strings lexicographically, ignoring case considerations.

This method returns an integer whose sign is that of this.toUpperCase().toLowerCase().compareTo( str.toUpperCase().toLowerCase()).

Note that this method does not take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides collators to allow locale-sensitive ordering.

Parameters:
str the String to be compared.
Returns:
a negative integer, zero, or a positive integer as the the specified String is greater than, equal to, or less than this String, ignoring case considerations.
See also:
java.text.Collator::compare(String, String)
Since:
1.2

jboolean java::lang::String::regionMatches ( jint  toffset,
const String other,
jint  ooffset,
jint  len 
) const

Tests if two string regions are equal.

A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true:

jboolean java::lang::String::regionMatchesIgnoreCase ( jint  toffset,
const String other,
jint  ooffset,
jint  len 
) const

Tests if two string regions are equal.

A substring of this String object is compared to a substring of the argument other. The result is true if these substrings represent character sequences that are the same, ignoring case if and only if ignoreCase is true. The substring of this String object to be compared begins at index toffset and has length len. The substring of other to be compared begins at index ooffset and has length len. The result is false if and only if at least one of the following is true:

Parameters:
toffset the starting offset of the subregion in this string.
other the string argument.
ooffset the starting offset of the subregion in the string argument.
len the number of characters to compare.
Returns:
true if the specified subregion of this string matches the specified subregion of the string argument; false otherwise. Whether the matching is exact or case insensitive depends on the ignoreCase argument.

jboolean java::lang::String::startsWith ( const String prefix,
jint  toffset = 0 
) const

Tests if this string starts with the specified prefix beginning a specified index.

Parameters:
prefix the prefix.
toffset where to begin looking in the string.
Returns:
true if the character sequence represented by the argument is a prefix of the substring of this object starting at index toffset; false otherwise. The result is false if toffset is negative or greater than the length of this String object; otherwise the result is the same as the result of the expression
          this.subString(toffset).startsWith(prefix)
          
Exceptions:
java.lang.NullPointerException if prefix is null.

jboolean java::lang::String::endsWith ( const String suffix  )  const

Tests if this string ends with the specified suffix.

Parameters:
suffix the suffix.
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise. Note that the result will be true if the argument is the empty string or is equal to this String object as determined by the equals(Object) method.
Exceptions:
java.lang.NullPointerException if suffix is null.

jint java::lang::String::indexOf ( jchar  ch,
jint  fromIndex = 0 
) const

Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex, then the index of the first such occurrence is returned--that is, the smallest value k such that: <blockquote>

 (this.charAt(k) == ch) && (k >= fromIndex)
 
</blockquote> is true. If no such character occurs in this string at or after position fromIndex, then -1 is returned.

There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.

Parameters:
ch a character.
fromIndex the index to start the search from.
Returns:
the index of the first occurrence of the character in the character sequence represented by this object that is greater than or equal to fromIndex, or -1 if the character does not occur.

jint java::lang::String::lastIndexOf ( jchar  ch,
jint  fromIndex = -1 
) const

Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index.

That is, the index returned is the largest value k such that: <blockquote>

 this.charAt(k) == ch) && (k <= fromIndex)
 
</blockquote> is true.

Parameters:
ch a character.
fromIndex the index to start the search from. There is no restriction on the value of fromIndex. If it is greater than or equal to the length of this string, it has the same effect as if it were equal to one less than the length of this string: this entire string may be searched. If it is negative, it has the same effect as if it were -1: -1 is returned.
Returns:
the index of the last occurrence of the character in the character sequence represented by this object that is less than or equal to fromIndex, or -1 if the character does not occur before that point.

jint java::lang::String::indexOf ( const String str,
jint  fromIndex = 0 
) const

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index.

The integer returned is the smallest value k such that: <blockquote>

 this.startsWith(str, k) && (k >= fromIndex)
 
</blockquote> is true.

There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.

Parameters:
str the substring to search for.
fromIndex the index to start the search from.
Returns:
If the string argument occurs as a substring within this object at a starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.
Exceptions:
java.lang.NullPointerException if str is null

jint java::lang::String::lastIndexOf ( const String str,
jint  fromIndex = -1 
) const

Returns the index within this string of the last occurrence of the specified substring.

The returned index indicates the start of the substring, and it must be equal to or less than fromIndex. That is, the index returned is the largest value k such that: <blockquote>

 this.startsWith(str, k) && (k <= fromIndex)
 
</blockquote>

Parameters:
str the substring to search for.
fromIndex the index to start the search from. There is no restriction on the value of fromIndex. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: this entire string may be searched. If it is negative, it has the same effect as if it were -1: -1 is returned.
Returns:
If the string argument occurs one or more times as a substring within this object at a starting index no greater than fromIndex, then the index of the first character of the last such substring is returned. If it does not occur as a substring starting at fromIndex or earlier, -1 is returned.
Exceptions:
java.lang.NullPointerException if str is null.

String java::lang::String::substring ( jint  beginIndex,
jint  endIndex = -1 
) const

Returns a new string that is a substring of this string.

The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Examples: <blockquote>

 "hamburger".substring(4, 8) returns "urge"
 "smiles".substring(1, 5) returns "mile"
 
</blockquote>

Parameters:
beginIndex the beginning index, inclusive.
endIndex the ending index, exclusive.
Returns:
the specified substring.
Exceptions:
IndexOutOfBoundsException if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.

String java::lang::String::concat ( const String str  )  const

Concatenates the specified string to the end of this string.

If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.

Examples: <blockquote>

 "cares".concat("s") returns "caress"
 "to".concat("get").concat("her") returns "together"
 
</blockquote>

Parameters:
str the String that is concatenated to the end of this String.
Returns:
a string that represents the concatenation of this object's characters followed by the string argument's characters.
Exceptions:
java.lang.NullPointerException if str is null.

String java::lang::String::replace ( jchar  oldChar,
jchar  newChar 
) const

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.

If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.

Examples: <blockquote>

 "mesquite in your cellar".replace('e', 'o')
         returns "mosquito in your collar"
 "the war of baronets".replace('r', 'y')
         returns "the way of bayonets"
 "sparring with a purple porpoise".replace('p', 't')
         returns "starring with a turtle tortoise"
 "JonL".replace('q', 'x') returns "JonL" (no change)
 
</blockquote>

Parameters:
oldChar the old character.
newChar the new character.
Returns:
a string derived from this string by replacing every occurrence of oldChar with newChar.

String java::lang::String::toLowerCase (  )  const

Converts all of the characters in this String to lower case using the rules of the default locale, which is returned by Locale.getDefault.

If no character in the string has a different lowercase version, based on calling the toLowerCase method defined by Character, then the original string is returned.

Otherwise, this method creates a new String object that represents a character sequence identical in length to the character sequence represented by this String object, with every character equal to the result of applying the method Character.toLowerCase to the corresponding character of this String object.

Examples: <blockquote>

 "French Fries".toLowerCase() returns "french fries"
 "<img src="doc-files/capiota.gif"><img src="doc-files/capchi.gif">
captheta.gif
capupsil.gif
capsigma.gif
".toLowerCase() returns "
iota.gif
chi.gif
theta.gif
upsilon.gif
sigma1.gif
"
</blockquote>

Returns:
the string, converted to lowercase.

String java::lang::String::toUpperCase (  )  const

Converts all of the characters in this String to upper case using the rules of the default locale, which is returned by Locale.getDefault.

If no character in this string has a different uppercase version, based on calling the toUpperCase method defined by Character, then the original string is returned.

Otherwise, this method creates a new String object representing a character sequence identical in length to the character sequence represented by this String object and with every character equal to the result of applying the method Character.toUpperCase to the corresponding character of this String object.

Examples: <blockquote>

 "Fahrvergnügen".toUpperCase() returns "FAHRVERGNÜGEN"
 "Visit Ljubinje!".toUpperCase() returns "VISIT LJUBINJE!"
 
</blockquote>

Returns:
the string, converted to uppercase.

String java::lang::String::trim (  )  const

Removes white space from both ends of this string.

If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '&#92;u0020' (the space character), then a reference to this String object is returned.

Otherwise, if there is no character with a code greater than '&#92;u0020' in the string, then a new String object representing an empty string is created and returned.

Otherwise, let k be the index of the first character in the string whose code is greater than '&#92;u0020', and let m be the index of the last character in the string whose code is greater than '&#92;u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(km+1).

This method may be used to trim whitespace from the beginning and end of a string; in fact, it trims all ASCII control characters as well.

Returns:
this string, with white space removed from the front and end.

jint java::lang::String::capacity (  )  const

Returns the current capacity of the String buffer.

The capacity is the amount of storage available for newly inserted characters; beyond which an allocation will occur.

Returns:
the current capacity of this string buffer.

void java::lang::String::ensureCapacity ( jint  minimumCapacity  ) 

Ensures that the capacity of the buffer is at least equal to the specified minimum.

If the current capacity of this string buffer is less than the argument, then a new internal buffer is allocated with greater capacity. The new capacity is the larger of:

If the minimumCapacity argument is nonpositive, this method takes no action and simply returns.

Parameters:
minimumCapacity the minimum desired capacity.

void java::lang::String::setLength ( jint  newLength  ) 

Sets the length of this String buffer.

This string buffer is altered to represent a new character sequence whose length is specified by the argument. For every nonnegative index k less than newLength, the character at index k in the new character sequence is the same as the character at index k in the old sequence if k is less than the length of the old character sequence; otherwise, it is the null character ''.

In other words, if the newLength argument is less than the current length of the string buffer, the string buffer is truncated to contain exactly the number of characters given by the newLength argument.

If the newLength argument is greater than or equal to the current length, sufficient null characters ('&#92;u0000') are appended to the string buffer so that length becomes the newLength argument.

The newLength argument must be greater than or equal to 0.

Parameters:
newLength the new length of the buffer.
Exceptions:
IndexOutOfBoundsException if the newLength argument is negative.
See also:
java.lang.StringBuffer::length()

void java::lang::String::setCharAt ( jint  index,
jchar  ch 
)

The character at the specified index of this string buffer is set to ch.

The string buffer is altered to represent a new character sequence that is identical to the old character sequence, except that it contains the character ch at position index.

The offset argument must be greater than or equal to 0, and less than the length of this string buffer.

Parameters:
index the index of the character to modify.
ch the new character.
Exceptions:
IndexOutOfBoundsException if index is negative or greater than or equal to length().
See also:
java.lang.StringBuffer::length()

String& java::lang::String::append ( const String src  ) 

Appends the string to this string buffer.

The characters of the String argument are appended, in order, to the contents of this string buffer, increasing the length of this string buffer by the length of the argument. If str is null, then the four characters "null" are appended to this string buffer.

Let n be the length of the old character sequence, the one contained in the string buffer just prior to execution of the append method. Then the character at index k in the new character sequence is equal to the character at index k in the old character sequence, if k is less than n; otherwise, it is equal to the character at index k-n in the argument str.

Parameters:
str a string.
Returns:
a reference to this StringBuffer.

String& java::lang::String::remove ( jint  start,
jint  end = -1 
)

Removes the characters in a substring of this StringBuffer.

The substring begins at the specified start and extends to the character at index end - 1 or to the end of the StringBuffer if no such character exists. If start is equal to end, no changes are made.

Parameters:
start The beginning index, inclusive.
end The ending index, exclusive.
Returns:
This string buffer.
Exceptions:
StringIndexOutOfBoundsException if start is negative, greater than length(), or greater than end.
Since:
1.2

String& java::lang::String::removeCharAt ( int  index  ) 

Removes the character at the specified position in this StringBuffer (shortening the StringBuffer by one character).

Parameters:
index Index of character to remove
Returns:
This string buffer.
Exceptions:
StringIndexOutOfBoundsException if the index is negative or greater than or equal to length().
Since:
1.2

String& java::lang::String::replace ( jint  start,
jint  end,
const String str 
)

Replaces the characters in a substring of this StringBuffer with characters in the specified String.

The substring begins at the specified start and extends to the character at index end - 1 or to the end of the StringBuffer if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start. (The StringBuffer will be lengthened to accommodate the specified String if necessary.)

Parameters:
start The beginning index, inclusive.
end The ending index, exclusive.
str String that will replace previous contents.
Returns:
This string buffer.
Exceptions:
StringIndexOutOfBoundsException if start is negative, greater than length(), or greater than end.
Since:
1.2

String& java::lang::String::insert ( jint  offset,
const String str 
)

Inserts the string into this string buffer.

The characters of the String argument are inserted, in order, into this string buffer at the indicated offset, moving up any characters originally above that position and increasing the length of this string buffer by the length of the argument. If str is null, then the four characters "null" are inserted into this string buffer.

The character at index k in the new character sequence is equal to:

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset the offset.
str a string.
Returns:
a reference to this StringBuffer object.
Exceptions:
StringIndexOutOfBoundsException if the offset is invalid.
See also:
java.lang.StringBuffer::length()

String& java::lang::String::reverse (  ) 

The character sequence contained in this string buffer is replaced by the reverse of the sequence.

Let n be the length of the old character sequence, the one contained in the string buffer just prior to execution of the reverse method. Then the character at index k in the new character sequence is equal to the character at index n-k-1 in the old character sequence.

Returns:
a reference to this <codeStringBuffer object..
Since:
JDK1.0.2


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:56:41 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3