img
This method compares the invoking object with obj. It returns 0 if the values are equal. A
negative value is returned if the invoking object has a lower value. Otherwise, a positive
value is returned.
This interface is implemented by several of the classes already reviewed in this topic.
Specifically, the Byte, Character, Double, Float, Long, Short, String, and Integer classes
define a compareTo( ) method. In addition, as the next chapter explains, objects that implement
this interface can be used in various collections.
The Appendable Interface
Objects of a class that implements Appendable can have a character or character sequences
appended to it. Appendable defines these three methods:
Appendable append(char ch) throws IOException
Appendable append(CharSequence chars) throws IOException
Appendable append(CharSequence chars, int begin, int end) throws IOException
In the first form, the character ch is appended to the invoking object. In the second form, the
character sequence chars is appended to the invoking object. The third form allows you to
indicate a portion (specified by begin and end) of the sequence specified by chars. In all cases,
a reference to the invoking object is returned.
The Iterable Interface
Iterable must be implemented by any class whose objects will be used by the for-each
version of the for loop. In other words, in order for an object to be used within a for-each
style for loop, its class must implement Iterable. Iterable is a generic interface that has this
declaration:
interface Iterable<T>
Here, T is the type of the object being iterated. It defines one method, iterator( ), which is
shown here:
Iterator<T> iterator( )
It returns an iterator to the elements contained in the invoking object.
NOTE  Iterators are described in detail in Chapter 17.
OTE
The Readable Interface
The Readable interface indicates that an object can be used as a source for characters.
It defines one method called read( ), which is shown here:
int read(CharBuffer buf) throws IOException
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home