Name
String
Synopsis
This class represents a immutable character string. Operations on
String
objects that change their content actually
place their results in other String
objects.
When concatenating strings or changing the values of characters within
a string, it is more efficient to use a StringBuffer
instead.
The CLDC String
class is similar to its J2SE equivalent,
but lacks the following methods: compareToIgnoreCase()
,
copyValueOf()
, equalsIgnoreCase()
and
intern()
. It also does not contain the variants of
lastIndexOf()
that accept a String
-
valued argument, or the valueOf()
methods for
types float
and double
.
A String
can be constructed as a copy of another
String
, from the content of a
StringBuffer
, or from an array of characters or bytes.
When constructing a String
from bytes, the appropriate
character encoding must be used; if an encoding is not specified, the
platform’s default encoding is assumed. A String
can
also be created by applying the static valueOf()
methods
to a boolean
, a char
, an array of
characters (char[]
), an int
, a
long
or an arbitrary Java Object
.
With an Object
, the String
is
created using the return value of the object’s toString()
method.
The toCharArray()
method returns an array of
char
s initialized with the content of the
String
. The getChars()
method is
similar, but requires the caller to allocate the destination array and can be
used to extract a subset of the string. The getBytes()
methods copy a subset of the String
into a pre-allocated byte ...
Get J2ME in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.