Java The Complete Reference, Seventh Edition

(Greg DeLong) #1

Boolean


Booleanis a very thin wrapper aroundbooleanvalues, which is useful mostly when you
want to pass abooleanvariable by reference. It contains the constantsTRUEandFALSE,
which define true and falseBooleanobjects.Booleanalso defines theTYPEfield, which is
theClassobject forboolean.Booleandefines these constructors:

Boolean(booleanboolValue)
Boolean(StringboolString)

In the first version,boolValuemust be eithertrueorfalse. In the second version, ifboolString
contains the string “true” (in uppercase or lowercase), then the newBooleanobject will be
true. Otherwise, it will be false.
Booleandefines the methods shown in Table 16-9.

402 Part II: The Java Library


Method Description
static boolean isLowSurrogate(charch) Returnstrueifchcontains a valid low
surrogate character.
static boolean
isSupplementar yCodePoint(intcp)

Returnstrueifcpcontains a supplemental
character.
static boolean
isSurrogatePair(charhighCh, charlowCh)

ReturnstrueifhighChandlowChform a valid
surrogate pair.
static boolean isValidCodePoint(intcp) Returnstrueifcpcontains a valid code point.
static char[ ] toChars(intcp) Converts the code point incpinto itschar
equivalent, which might require twochars.
An array holding the result is returned.
static int
toChars(intcp, chartarget[ ], intloc)

Converts the code point incpinto itschar
equivalent, storing the result intarget,beginning
atloc.Returns 1 ifcpcan be represented by a
singlechar. It returns 2 other wise.
static int
toCodePoint(charhighCh, charlowCh)

ConvertshighChandlowChinto their equivalent
code point.

TABLE 16-8 A Sampling of Methods That Provide Suppor t for 32-Bit Unicode Code Points(continued)

Method Description
boolean booleanValue( ) Returnsbooleanequivalent.
int compareTo(Booleanb) Returns zero if the invoking object andbcontain the
same value. Returns a positive value if the invoking
object istrueandbisfalse. Other wise, returns a
negative value.
boolean equals(ObjectboolObj) Returnstrueif the invoking object is equivalent to
boolObj.Other wise, it returnsfalse.

TABLE 16-9 The Methods Defined byBoolean
Free download pdf