Java Reference
In-Depth Information
String and StringBuffer
Both
String
and
StringBuffer
are present in the CLDC
java.lang
package. They are largely
unchanged from their J2SE counterparts.
The largest change in the
String
class in CLDC 1.0 is the elimination of
valueOf()
static
methods that convert between floating-point primitives and
String
s, although these are present in
CLDC 1.1. A few other obscure methods are absent from CLDC's
String
class, but you probably
won't miss them. For example, although CLDC's
String
includes the
compareTo(String str)
method, it doesn't have either the
compareTo(Object o)
or
compareToIgnoreCase(String str)
methods that are found in the J2SE SDK. (CLDC 1.1 does include an
equalsIgnoreCase()
method
in the
String
class.) There are simple workarounds for these limitations. You can, for example,
call the
toString()
method on an object and pass it to
compareTo(String str)
.
StringBuffer
's
append()
and
insert()
methods do not include overrides for floating-point
types in the CLDC 1.0 version of the class, but these are available in CDLC 1.1. Also, the
substring()
method has been pruned. Other than that, however,
StringBuffer
should be very familiar for
seasoned J2SE programmers.
Math
The
Math
class contains static methods for performing mathematical calculations. In J2SE, many
of these methods involve trigonometric functions on floating-point numbers. In CLDC 1.0,
these are all gone, leaving only a handful of methods. CLDC 1.1, because it supports floating-
point types, includes several more methods in
java.lang.Math
, but CLDC's
java.lang.Math
is
still a subset of the J2SE version of the class. In the API listing that follows, the plus signs (+)
indicate new variables or methods in CLDC 1.1.
public final class Math
extends java.lang.Object {
// Constants
+ public static final double E;
+ public static final double PI;
// Static methods
public static int abs(int a);
public static long abs(long a);
+ public static float abs(float a);
+ public static double abs(double a);
+ public static native double ceil(double a);
+ public static native double cos(double a);
+ public static native double floor(double a);
public static int max(int a, int b);
public static long max(long a, long b);
+ public static float max(float a, float b);
+ public static double max(double a, double b);
public static int min(int a, int b);
public static long min(long a, long b);
+ public static float min(float a, float b);
+ public static double min(double a, double b);
+ public static native double sin(double a);
Search WWH ::
Custom Search