O'Reilly logo

J2ME in a Nutshell by Kim Topley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 chars 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required