Java Reference
In-Depth Information
Character type
Description
char
Primitive data type.
Wrapper class for
char
.
Character
This class support a buffer of
char
providing methods for get/put characters or a sequence of characters operations.
CharBuffer
CharSequence
An interface implemented by
CharBuffer
,
Segment
,
String
,
StringBuffer
and
StringBuilder
. It supports
read-only access to a sequence of chars.
Java also provides a number of classes and interfaces to support strings. These are sum-
marized in the following table. We will use these in many of our examples. The
String
,
StringBuffer
, and
StringBuilder
classes provide similar string processing cap-
abilities but differ in whether they can be modified and whether they are thread-safe. The
CharacterIterator
interface and the
StringCharacterIterator
class
provide techniques to traverse character sequences.
The
Segment
class represents a fragment of text.
Class/Interface
Description
String
An immutable string.
StringBuffer
Represents a modifiable string. It is thread-safe.
StringBuilder
Compatible with the
StringBuffer
class but is not thread-safe.
Segment
Represents a fragment of text in a character array. It provides rapid access to character data in an array.
CharacterIterator
Defines an iterator for text. It supports bidirectional traversal of text.
StringCharacterIterator
A class that implements the
CharacterIterator
interface for a
String
.
We also need to consider the file format if we are reading from a file. Often data is ob-
tained from sources where the words are annotated. For example, if we use a web page as