img
Method
Description
int of fsetByCodePoints(int star t, int num)
Returns the index with the invoking string that is num code
points beyond the star ting index specified by star t. Added by
J2SE 5.
CharSequence
Returns a substring of the invoking string, beginning at
subSequence(int star tIndex,
star tIndex and stopping at stopIndex. This method is required
int stopIndex)
by the CharSequence inter face, which is now implemented by
StringBuffer.
void trimToSize( )
Reduces the size of the character buf fer for the invoking object
to exactly fit the current contents. Added by J2SE 5.
Aside from subSequence( ), which implements a method required by the CharSequence
interface, the other methods allow a StringBuffer to be searched for an occurrence of a String.
The following program demonstrates indexOf( ) and lastIndexOf( ):
class IndexOfDemo {
public static void main(String args[]) {
StringBuffer sb = new StringBuffer("one two one");
int i;
i = sb.indexOf("one");
System.out.println("First index: " + i);
i = sb.lastIndexOf("one");
System.out.println("Last index: " + i);
}
}
The output is shown here:
First index: 0
Last index: 8
StringBuilder
J2SE 5 adds a new string class to Java's already powerful string handling capabilities. This
new class is called StringBuilder. It is identical to StringBuffer except for one important
difference: it is not synchronized, which means that it is not thread-safe. The advantage of
StringBuilder is faster performance. However, in cases in which you are using multithreading,
you must use StringBuffer rather than StringBuilder.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home