Tag Archives: Wrapper Class

java.lang.Boolean Class & Methods


The java.lang.Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean.  This class provides many methods for converting a boolean to a String and a String to a boolean, as well as other constants and methods useful when dealing with a boolean.

Boolean class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static Boolean FALSE :The Boolean object corresponding to the primitive value false.
  • static Boolean TRUE :The Boolean object corresponding to the primitive value true.
  • static Class TYPE :The Class object representing the primitive type boolean.

Constructors

  • Boolean(boolean value) :Allocates a Boolean object representing the value argument.
    Boolean(String s) :Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string “true”.

Methods

  • boolean booleanValue() :Returns the value of this Boolean object as a boolean primitive.
  • static int compare(boolean x, boolean y) :Compares two boolean values.
  • int compareTo(Boolean b) :Compares this Boolean instance with another.
  • boolean equals(Object obj) :Returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object.
  • static boolean getBoolean(String name) :Returns true if and only if the system property named by the argument exists and is equal to the string “true”.
  • int hashCode() :Returns a hash code for this Boolean object.
  • static boolean parseBoolean(String s) :Parses the string argument as a boolean.
  • String toString() :Returns a String object representing this Boolean’s value.
  • static String toString(boolean b) :Returns a String object representing the specified boolean.
  • static Boolean valueOf(boolean b) :Returns a Boolean instance representing the specified boolean value.
  • static Boolean valueOf(String s) :Returns a Boolean with a value represented by the specified string.

References

java.lang.Character Class & Methods


The java.lang.Character class wraps a value of the primitive type char in an object. An object of type Character contains a single field whose type is char.  This class provides several methods for determining a character’s category (lowercase letter, digit, etc.) and for converting characters from uppercase to lowercase and vice versa.

Character information is based on the Unicode Standard. The methods and data of class Character are defined by the information in the UnicodeData file that is part of the Unicode Character Database maintained by the Unicode Consortium. This file specifies various properties including name and general category for every defined Unicode code point or character range.

Character class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Sub Class

  • static class Character.Subset :Instances of this class represent particular subsets of the Unicode character set.
  • static class Character.UnicodeBlock :A family of character subsets representing the charater blocks in the Unicode specification.
  • static class Character.UnicodeScript :A family of character subsets representing the character scripts defined in the Unicode Standard Annex #24: Script Names.

Constants

  • static byte COMBINING_SPACING_MARK :General category “Mc” in the Unicode specification.
  • static byte CONNECTOR_PUNCTUATION :General category “Pc” in the Unicode specification.
  • static byte CONTROL :General category “Cc” in the Unicode specification.
  • static byte CURRENCY_SYMBOL :General category “Sc” in the Unicode specification.
  • static byte DASH_PUNCTUATION :General category “Pd” in the Unicode specification.
  • static byte DECIMAL_DIGIT_NUMBER :General category “Nd” in the Unicode specification.
  • static byte DIRECTIONALITY_ARABIC_NUMBER :Weak bidirectional character type “AN” in the Unicode specification.
  • static byte DIRECTIONALITY_BOUNDARY_NEUTRAL :Weak bidirectional character type “BN” in the Unicode specification.
  • static byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR :Weak bidirectional character type “CS” in the Unicode specification.
  • static byte DIRECTIONALITY_EUROPEAN_NUMBER :Weak bidirectional character type “EN” in the Unicode specification.
  • static byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR :Weak bidirectional character type “ES” in the Unicode specification.
  • static byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR :Weak bidirectional character type “ET” in the Unicode specification.
  • static byte DIRECTIONALITY_LEFT_TO_RIGHT :Strong bidirectional character type “L” in the Unicode specification.
  • static byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING :Strong bidirectional character type “LRE” in the Unicode specification.
  • static byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE :Strong bidirectional character type “LRO” in the Unicode specification.
  • static byte DIRECTIONALITY_NONSPACING_MARK :Weak bidirectional character type “NSM” in the Unicode specification.
  • static byte DIRECTIONALITY_OTHER_NEUTRALS :Neutral bidirectional character type “ON” in the Unicode specification.
  • static byte DIRECTIONALITY_PARAGRAPH_SEPARATOR :Neutral bidirectional character type “B” in the Unicode specification.
  • static byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT :Weak bidirectional character type “PDF” in the Unicode specification.
  • static byte DIRECTIONALITY_RIGHT_TO_LEFT :Strong bidirectional character type “R” in the Unicode specification.
  • static byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC :Strong bidirectional character type “AL” in the Unicode specification.\
  • static byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING :Strong bidirectional character type “RLE” in the Unicode specification.
  • static byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE :Strong bidirectional character type “RLO” in the Unicode specification.
  • static byte DIRECTIONALITY_SEGMENT_SEPARATOR :Neutral bidirectional character type “S” in the Unicode specification.
  • static byte DIRECTIONALITY_UNDEFINED :Undefined bidirectional character type.
  • static byte DIRECTIONALITY_WHITESPACE :Neutral bidirectional character type “WS” in the Unicode specification.
  • static byte ENCLOSING_MARK :General category “Me” in the Unicode specification.
  • static byte END_PUNCTUATION :General category “Pe” in the Unicode specification.
  • static byte FINAL_QUOTE_PUNCTUATION :General category “Pf” in the Unicode specification.
  • static byte FORMAT :General category “Cf” in the Unicode specification.
  • static byte INITIAL_QUOTE_PUNCTUATION :General category “Pi” in the Unicode specification.
  • static byte LETTER_NUMBER :General category “Nl” in the Unicode specification.
  • static byte LINE_SEPARATOR :General category “Zl” in the Unicode specification.
  • static byte LOWERCASE_LETTER :General category “Ll” in the Unicode specification.
  • static byte MATH_SYMBOL :General category “Sm” in the Unicode specification.
  • static int MAX_CODE_POINT :The maximum value of a Unicode code point, constant U+10FFFF.
  • static char MAX_HIGH_SURROGATE :The maximum value of a Unicode high-surrogate code unit in the UTF-16 encoding, constant ‘\uDBFF’.
  • static char MAX_LOW_SURROGATE :The maximum value of a Unicode low-surrogate code unit in the UTF-16 encoding, constant ‘\uDFFF’.
  • static int MAX_RADIX :The maximum radix available for conversion to and from strings.
  • static char MAX_SURROGATE :The maximum value of a Unicode surrogate code unit in the UTF-16 encoding, constant ‘\uDFFF’.
  • static char MAX_VALUE :The constant value of this field is the largest value of type char, ‘\uFFFF’.
  • static int MIN_CODE_POINT :The minimum value of a Unicode code point, constant U+0000.
  • static char MIN_HIGH_SURROGATE :The minimum value of a Unicode high-surrogate code unit in the UTF-16 encoding, constant ‘\uD800’.
  • static char MIN_LOW_SURROGATE :The minimum value of a Unicode low-surrogate code unit in the UTF-16 encoding, constant ‘\uDC00’.
  • static int MIN_RADIX :The minimum radix available for conversion to and from strings.
  • static int MIN_SUPPLEMENTARY_CODE_POINT :The minimum value of a Unicode supplementary code point, constant U+10000.
  • static char MIN_SURROGATE :The minimum value of a Unicode surrogate code unit in the UTF-16 encoding, constant ‘\uD800’.
  • static char MIN_VALUE :The constant value of this field is the smallest value of type char, ‘\u0000’.
  • static byte MODIFIER_LETTER :General category “Lm” in the Unicode specification.
  • static byte MODIFIER_SYMBOL :General category “Sk” in the Unicode specification.
  • static byte NON_SPACING_MARK :General category “Mn” in the Unicode specification.
  • static byte OTHER_LETTER :General category “Lo” in the Unicode specification.
  • static byte OTHER_NUMBER :General category “No” in the Unicode specification.
  • static byte OTHER_PUNCTUATION :General category “Po” in the Unicode specification.
  • static byte OTHER_SYMBOL :General category “So” in the Unicode specification.
  • static byte PARAGRAPH_SEPARATOR :General category “Zp” in the Unicode specification.
  • static byte PRIVATE_USE :General category “Co” in the Unicode specification.
  • static int SIZE :The number of bits used to represent a char value in unsigned binary form, constant 16.
  • static byte :SPACE_SEPARATOR :General category “Zs” in the Unicode specification.
  • static byte START_PUNCTUATION :General category “Ps” in the Unicode specification.
  • static byte SURROGATE :General category “Cs” in the Unicode specification.
  • static byte TITLECASE_LETTER :General category “Lt” in the Unicode specification.
  • static Class TYPE :The Class instance representing the primitive type char.
  • static byte UNASSIGNED :General category “Cn” in the Unicode specification.
  • static byte UPPERCASE_LETTER :General category “Lu” in the Unicode specification.

Constructors

  • Character(char value) :Constructs a newly allocated Character object that represents the specified char value.

Methods

  • static int charCount(int codePoint) :Determines the number of char values needed to represent the specified character (Unicode code point).
  • char charValue() :Returns the value of this Character object.\
  • static int codePointAt(char[] a, int index) :Returns the code point at the given index of the char array.
  • static int codePointAt(char[] a, int index, int limit) :Returns the code point at the given index of the char array, where only array elements with index less than limit can be used.
  • static int codePointAt(CharSequence seq, int index) :Returns the code point at the given index of the CharSequence.
  • static int codePointBefore(char[] a, int index) :Returns the code point preceding the given index of the char array.
  • static int codePointBefore(char[] a, int index, int start) :Returns the code point preceding the given index of the char array, where only array elements with index greater than or equal to start can be used.
  • static int codePointBefore(CharSequence seq, int index) :Returns the code point preceding the given index of the CharSequence.
  • static int codePointCount(char[] a, int offset, int count) :Returns the number of Unicode code points in a subarray of the char array argument.
  • static int codePointCount(CharSequence seq, int beginIndex, int endIndex) :Returns the number of Unicode code points in the text range of the specified char sequence.
  • static int compare(char x, char y) :Compares two char values numerically.
  • int compareTo(Character anotherCharacter) :Compares two Character objects numerically.
  • static int digit(char ch, int radix) :Returns the numeric value of the character ch in the specified radix.
  • static int digit(int codePoint, int radix) :Returns the numeric value of the specified character (Unicode code point) in the specified radix.
  • boolean equals(Object obj) :Compares this object against the specified object.
  • static char forDigit(int digit, int radix) :Determines the character representation for a specific digit in the specified radix.
  • static byte getDirectionality(char ch) :Returns the Unicode directionality property for the given character.
  • static byte getDirectionality(int codePoint) :Returns the Unicode directionality property for the given character (Unicode code point).
  • static String getName(int codePoint) :Returns the Unicode name of the specified character codePoint, or null if the code point is unassigned.
  • static int getNumericValue(char ch) :Returns the int value that the specified Unicode character represents.
  • static int getNumericValue(int codePoint) :Returns the int value that the specified character (Unicode code point) represents.
  • static int getType(char ch) :Returns a value indicating a character’s general category.
  • static int getType(int codePoint) :Returns a value indicating a character’s general category.
  • int hashCode() :Returns a hash code for this Character; equal to the result of invoking charValue().
  • static char highSurrogate(int codePoint) :Returns the leading surrogate (a high surrogate code unit) of the surrogate pair representing the specified supplementary character (Unicode code point) in the UTF-16 encoding.
  • static boolean isAlphabetic(int codePoint) :Determines if the specified character (Unicode code point) is an alphabet.
  • static boolean isBmpCodePoint(int codePoint) :Determines whether the specified character (Unicode code point) is in the Basic Multilingual Plane (BMP).
  • static boolean isDefined(char ch) :Determines if a character is defined in Unicode.
  • static boolean isDefined(int codePoint) :Determines if a character (Unicode code point) is defined in Unicode.
  • static boolean isDigit(char ch) :Determines if the specified character is a digit.
  • static boolean isDigit(int codePoint) :Determines if the specified character (Unicode code point) is a digit.
  • static boolean isHighSurrogate(char ch) :Determines if the given char value is a Unicode high-surrogate code unit (also known as leading-surrogate code unit).
  • boolean isIdentifierIgnorable(char ch) :Determines if the specified character should be regarded as an ignorable character in a Java identifier or a Unicode identifier.
  • static boolean isIdentifierIgnorable(int codePoint) :Determines if the specified character (Unicode code point) should be regarded as an ignorable character in a Java identifier or a Unicode identifier.
  • static boolean isIdeographic(int codePoint) :Determines if the specified character (Unicode code point) is a CJKV (Chinese, Japanese, Korean and Vietnamese) ideograph, as defined by the Unicode Standard.
  • static boolean isISOControl(char ch) :Determines if the specified character is an ISO control character.
  • static boolean isISOControl(int codePoint) :Determines if the referenced character (Unicode code point) is an ISO control character.
  • static boolean isJavaIdentifierPart(char ch) :Determines if the specified character may be part of a Java identifier as other than the first character.
  • static boolean isJavaIdentifierPart(int codePoint) :Determines if the character (Unicode code point) may be part of a Java identifier as other than the first character.
  • static boolean isJavaIdentifierStart(char ch) :Determines if the specified character is permissible as the first character in a Java identifier.
  • static boolean isJavaIdentifierStart(int codePoint) :Determines if the character (Unicode code point) is permissible as the first character in a Java identifier.
  • static boolean isJavaLetter(char ch) :Deprecated. Replaced by isJavaIdentifierStart(char).
  • static boolean isJavaLetterOrDigit(char ch) :Deprecated. Replaced by isJavaIdentifierPart(char).
  • static boolean isLetter(char ch) :Determines if the specified character is a letter.
  • static boolean isLetter(int codePoint) :Determines if the specified character (Unicode code point) is a letter.
  • static boolean isLetterOrDigit(char ch) :Determines if the specified character is a letter or digit.
  • static boolean isLetterOrDigit(int codePoint) :Determines if the specified character (Unicode code point) is a letter or digit.
  • static boolean isLowerCase(char ch) :Determines if the specified character is a lowercase character.
  • static boolean isLowerCase(int codePoint) :Determines if the specified character (Unicode code point) is a lowercase character.
  • static boolean isLowSurrogate(char ch) :Determines if the given char value is a Unicode low-surrogate code unit (also known as trailing-surrogate code unit).
  • static boolean isMirrored(char ch) :Determines whether the character is mirrored according to the Unicode specification.
  • static boolean isMirrored(int codePoint) :Determines whether the specified character (Unicode code point) is mirrored according to the Unicode specification.
  • static boolean isSpace(char ch) :Deprecated. Replaced by isWhitespace(char).\
  • static boolean isSpaceChar(char ch) :Determines if the specified character is a Unicode space character.
  • static boolean isSpaceChar(int codePoint) :Determines if the specified character (Unicode code point) is a Unicode space character.
  • static boolean isSupplementaryCodePoint(int codePoint) :Determines whether the specified character (Unicode code point) is in the supplementary character range.
  • static boolean isSurrogate(char ch) :Determines if the given char value is a Unicode surrogate code unit.
  • static boolean isSurrogatePair(char high, char low) :Determines whether the specified pair of char values is a valid Unicode surrogate pair.
  • static boolean isTitleCase(char ch) :Determines if the specified character is a titlecase character.\
  • static boolean :isTitleCase(int codePoint) :Determines if the specified character (Unicode code point) is a titlecase character.
  • static boolean isUnicodeIdentifierPart(char ch) :Determines if the specified character may be part of a Unicode identifier as other than the first character.
  • static boolean isUnicodeIdentifierPart(int codePoint) :Determines if the specified character (Unicode code point) may be part of a Unicode identifier as other than the first character.
  • static boolean isUnicodeIdentifierStart(char ch) :Determines if the specified character is permissible as the first character in a Unicode identifier.
  • static boolean isUnicodeIdentifierStart(int codePoint) :Determines if the specified character (Unicode code point) is permissible as the first character in a Unicode identifier.
  • boolean isUpperCase(char ch) :Determines if the specified character is an uppercase character.
  • static boolean isUpperCase(int codePoint) :Determines if the specified character (Unicode code point) is an uppercase character.
  • static boolean isValidCodePoint(int codePoint) :Determines whether the specified code point is a valid Unicode code point value.
  • static boolean isWhitespace(char ch) :Determines if the specified character is white space according to Java.
  • static boolean isWhitespace(int codePoint) :Determines if the specified character (Unicode code point) is white space according to Java.
  • static char lowSurrogate(int codePoint) :Returns the trailing surrogate (a low surrogate code unit) of the surrogate pair representing the specified supplementary character (Unicode code point) in the UTF-16 encoding.
  • static int offsetByCodePoints(char[] a, int start, int count, int index, int codePointOffset) :Returns the index within the given char subarray that is offset from the given index by codePointOffset code points.
  • static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) :Returns the index within the given char sequence that is offset from the given index by codePointOffset code points.
  • static char reverseBytes(char ch) :Returns the value obtained by reversing the order of the bytes in the specified char value.
  • static char[] toChars(int codePoint) :Converts the specified character (Unicode code point) to its UTF-16 representation stored in a char array.
  • static int toChars(int codePoint, char[] dst, int dstIndex) :Converts the specified character (Unicode code point) to its UTF-16 representation.
  • static int toCodePoint(char high, char low) :Converts the specified surrogate pair to its supplementary code point value.
  • static char toLowerCase(char ch) :Converts the character argument to lowercase using case mapping information from the UnicodeData file.
  • static int toLowerCase(int codePoint) :Converts the character (Unicode code point) argument to lowercase using case mapping information from the UnicodeData file.
  • String toString() :Returns a String object representing this Character’s value.
  • static String toString(char c) :Returns a String object representing the specified char.
  • static char toTitleCase(char ch) :Converts the character argument to titlecase using case mapping information from the UnicodeData file.
  • static int toTitleCase(int codePoint) :Converts the character (Unicode code point) argument to titlecase using case mapping information from the UnicodeData file.
  • static char toUpperCase(char ch) :Converts the character argument to uppercase using case mapping information from the UnicodeData file.
  • static int toUpperCase(int codePoint) :Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.
  • static Character valueOf(char c) :Returns a Character instance representing the specified char value.

References

java.lang.Short Class & Methods


The java.lang.Short class wraps a value of primitive type short in an object. An object of type Short contains a single field whose type is short. This class provides several utility methods for converting a short to a String and a String to a short, as well as other constants and methods useful when dealing with a short.

Short class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static short MAX_VALUE :A constant holding the maximum value a short can have, 215-1.
  • static short MIN_VALUE :A constant holding the minimum value a short can have, -215.
  • static int SIZE :The number of bits used to represent a short value in two’s complement binary form.
  • static Class TYPE :The Class instance representing the primitive type short.

Constructors

  • Short(short value) :Constructs a newly allocated Short object that represents the specified short value.
  • Short(String s) :Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Methods

  • byte byteValue() :Returns the value of this Short as a byte.
  • static int compare(short x, short y) :Compares two short values numerically.
  • int compareTo(Short anotherShort) :Compares two Short objects numerically.
  • static Short decode(String nm) :Decodes a String into a Short.
  • double doubleValue() :Returns the value of this Short as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Short as a float.
  • int hashCode() :Returns a hash code for this Short; equal to the result of invoking intValue().
  • int intValue() :Returns the value of this Short as an int.
  • long longValue() :Returns the value of this Short as a long.
  • static short parseShort(String s) :Parses the string argument as a signed decimal short.
  • static short parseShort(String s, int radix) :Parses the string argument as a signed short in the radix specified by the second argument.
  • static short reverseBytes(short i) :Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified short value.
  • short shortValue() :Returns the value of this Short as a short.
  • String toString() :Returns a String object representing this Short’s value.
  • String toString(short s) :Returns a new String object representing the specified short.
  • static Short valueOf(short s) :Returns a Short instance representing the specified short value.
  • static Short valueOf(String s) :Returns a Short object holding the value given by the specified String.
  • static Short valueOf(String s, int radix) :Returns a Short object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References

java.lang.Long Class & Methods


The java.lang.Long class wraps a value of the primitive type long in an object. An object of type Long contains a single field whose type is long.
This class provides several utility methods for converting a long to a String and a String to a long, as well as other constants and methods useful when dealing with a long.

Long class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static long MAX_VALUE :A constant holding the maximum value a long can have, 263-1.
  • static long MIN_VALUE :A constant holding the minimum value a long can have, -263.
  • static int SIZE :The number of bits used to represent a long value in two’s complement binary form.
  • static Class TYPE :The Class instance representing the primitive type long.

Constructors

  • Long(long value) :Constructs a newly allocated Long object that represents the specified long argument.
  • Long(String s) :Constructs a newly allocated Long object that represents the long value indicated by the String parameter.

Methods

  • static int bitCount(long i) :Returns the number of one-bits in the two’s complement binary representation of the specified long value.
  • byte byteValue() :Returns the value of this Long as a byte.
  • static int compare(long x, long y) :Compares two long values numerically.
  • int compareTo(Long anotherLong) :Compares two Long objects numerically.
  • static Long decode(String nm) :Decodes a String into a Long.
  • double doubleValue() :Returns the value of this Long as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Long as a float.
  • static Long getLong(String nm) :Determines the long value of the system property with the specified name.
  • static Long getLong(String nm, long val) :Determines the long value of the system property with the specified name.
  • static Long getLong(String nm, Long val) :Returns the long value of the system property with the specified name.
  • int hashCode() :Returns a hash code for this Long.
  • static long highestOneBit(long i) :Returns a long value with at most a single one-bit, in the position of the highest-order (“leftmost”) one-bit in the specified long value.
  • int intValue() :Returns the value of this Long as an int.
  • long longValue() :Returns the value of this Long as a long value.
  • static long lowestOneBit(long i) :Returns a long value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified long value.
  • static int numberOfLeadingZeros(long i) :Returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified long value.
  • static int numberOfTrailingZeros(long i) :Returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified long value.
  • static long parseLong(String s) :Parses the string argument as a signed decimal long.
  • static long parseLong(String s, int radix) :Parses the string argument as a signed long in the radix specified by the second argument.
  • static long reverse(long i) :Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified long value.
  • static long reverseBytes(long i) :Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified long value.
  • static long rotateLeft(long i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified long value left by the specified number of bits.
  • static long rotateRight(long i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified long value right by the specified number of bits.
  • short shortValue() :Returns the value of this Long as a short.
  • static int signum(long i) :Returns the signum function of the specified long value.
  • static String toBinaryString(long i) :Returns a string representation of the long argument as an unsigned integer in base 2.
  • static String toHexString(long i) :Returns a string representation of the long argument as an unsigned integer in base 16.
  • static String toOctalString(long i) :Returns a string representation of the long argument as an unsigned integer in base 8.
  • String toString() :Returns a String object representing this Long’s value.
  • static String toString(long i) :Returns a String object representing the specified long.
  • static String toString(long i, int radix) :Returns a string representation of the first argument in the radix specified by the second argument.
  • static Long valueOf(long l) :Returns a Long instance representing the specified long value.
  • static Long valueOf(String s) :Returns a Long object holding the value of the specified String.
  • static Long valueOf(String s, int radix) :Returns a Long object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References

 

java.lang.Integer Class & Methods


The java.lang.Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int. This class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.

Integer class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static int MAX_VALUE :A constant holding the maximum value an int can have, 231-1.
  • static int MIN_VALUE :A constant holding the minimum value an int can have, -231.
  • static int SIZE :The number of bits used to represent an int value in two’s complement binary form.
  • static Class TYPE :The Class instance representing the primitive type int.

Constructors

  • Integer(int value) :Constructs a newly allocated Integer object that represents the specified int value.
  • Integer(String s) :Constructs a newly allocated Integer object that represents the int value indicated by the String parameter.

Methods

  • static int bitCount(int i) :Returns the number of one-bits in the two’s complement binary representation of the specified int value.
  • byte byteValue() :Returns the value of this Integer as a byte.
  • static int compare(int x, int y) :Compares two int values numerically
  • int compareTo(Integer anotherInteger) :Compares two Integer objects numerically.
  • static Integer decode(String nm) :Decodes a String into an Integer.
  • double doubleValue() :Returns the value of this Integer as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Integer as a float.
  • static Integer getInteger(String nm) :Determines the integer value of the system property with the specified name.
  • static Integer getInteger(String nm, int val) :Determines the integer value of the system property with the specified name.
  • static Integer getInteger(String nm, Integer val) :Returns the integer value of the system property with the specified name.
  • int hashCode() :Returns a hash code for this Integer.
  • static int highestOneBit(int i) :Returns an int value with at most a single one-bit, in the position of the highest-order (“leftmost”) one-bit in the specified int value.
  • int intValue() :Returns the value of this Integer as an int.
  • long longValue() :Returns the value of this Integer as a long.
  • static int lowestOneBit(int i) :Returns an int value with at most a single one-bit, in the position of the lowest-order (“rightmost”) one-bit in the specified int value.
  • static int numberOfLeadingZeros(int i) :Returns the number of zero bits preceding the highest-order (“leftmost”) one-bit in the two’s complement binary representation of the specified int value.
  • static int numberOfTrailingZeros(int i) :Returns the number of zero bits following the lowest-order (“rightmost”) one-bit in the two’s complement binary representation of the specified int value.
  • static int parseInt(String s) :Parses the string argument as a signed decimal integer.
  • static int parseInt(String s, int radix) :Parses the string argument as a signed integer in the radix specified by the second argument.
  • static int reverse(int i) :Returns the value obtained by reversing the order of the bits in the two’s complement binary representation of the specified int value.
  • static int reverseBytes(int i) :Returns the value obtained by reversing the order of the bytes in the two’s complement representation of the specified int value.
  • static int rotateLeft(int i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified int value left by the specified number of bits.
  • static int rotateRight(int i, int distance) :Returns the value obtained by rotating the two’s complement binary representation of the specified int value right by the specified number of bits.
  • short shortValue() :Returns the value of this Integer as a short.
  • static int signum(int i) :Returns the signum function of the specified int value.
  • static String toBinaryString(int i) :Returns a string representation of the integer argument as an unsigned integer in base 2.
  • static String toHexString(int i) :Returns a string representation of the integer argument as an unsigned integer in base 16
  • static String toOctalString(int i) :Returns a string representation of the integer argument as an unsigned integer in base 8.
  • String toString() :Returns a String object representing this Integer’s value.
  • static String toString(int i) :Returns a String object representing the specified integer.
  • static String toString(int i, int radix) :Returns a string representation of the first argument in the radix specified by the second argument
  • static Integer valueOf(int i) :Returns an Integer instance representing the specified int value.
  • static Integer valueOf(String s) :Returns an Integer object holding the value of the specified String
  • static Integer valueOf(String s, int radix) :Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References

 

java.lang.Float Class and Methods


The java.lang.Float class wraps a value of primitive type float in an object. An object of type Float contains a single field whose type is float. This class provides several utility methods for converting a float to a String and a String to a float, as well as other constants and methods useful when dealing with a float.

Float class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static int MAX_EXPONENT :Maximum exponent a finite float variable may have.
  • static float MAX_VALUE :A constant holding the largest positive finite value of type float, (2-2-23)·2127.
  • static int MIN_EXPONENT :Minimum exponent a normalized float variable may have.
  • static float MIN_NORMAL :A constant holding the smallest positive normal value of type float, 2-126.
  • static float MIN_VALUE :A constant holding the smallest positive nonzero value of type float, 2-149.
  • static float NaN :A constant holding a Not-a-Number (NaN) value of type float.
  • static float NEGATIVE_INFINITY :A constant holding the negative infinity of type float.
  • static float POSITIVE_INFINITY : constant holding the positive infinity of type float
  • static int SIZE :The number of bits used to represent a float value.
  • static Class TYPE :The Class instance representing the primitive type float.

Constructors

  • Float(double value) :Constructs a newly allocated Float object that represents the argument converted to type float.
  • Float(float value) :Constructs a newly allocated Float object that represents the primitive float argument.
  • Float(String s) :Constructs a newly allocated Float object that represents the floating-point value of type float represented by the string.

Methods

  • byte byteValue() :Returns the value of this Float as a byte (by casting to a byte).
  • static int compare(float f1, float f2) :Compares the two specified float values.
  • int compareTo(Float anotherFloat) Compares two Float objects numerically.
  • double doubleValue() :Returns the double value of this Float object.
  • boolean equals(Object obj) :Compares this object against the specified object.
  • static int floatToIntBits(float value) :Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout.
  • static int floatToRawIntBits(float value) :Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout, preserving Not-a-Number (NaN) values.
  • float floatValue() :Returns the float value of this Float object.
  • int hashCode() :Returns a hash code for this Float object.
  • static float intBitsToFloat(int bits) :Returns the float value corresponding to a given bit representation.
  • int intValue() :Returns the value of this Float as an int (by casting to type int).
  • boolean isInfinite() :Returns true if this Float value is infinitely large in magnitude, false otherwise.
  • static boolean isInfinite(float v) :Returns true if the specified number is infinitely large in magnitude, false otherwise.
  • boolean isNaN() :Returns true if this Float value is a Not-a-Number (NaN), false otherwise.
  • static boolean isNaN(float v) :Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
  • long longValue() :Returns value of this Float as a long (by casting to type long).
  • static float parseFloat(String s) :Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float.
  • short shortValue() :Returns the value of this Float as a short (by casting to a short).
  • static String toHexString(float f) :Returns a hexadecimal string representation of the float argument.
  • String toString() :Returns a string representation of this Float object.
  • static String toString(float f) :Returns a string representation of the float argument.
  • static Float valueOf(float f) :Returns a Float instance representing the specified float value.
  • static Float valueOf(String s) :Returns a Float object holding the float value represented by the argument string s.

Exceptions

References

java.lang.Double Class & Methods


The java.lang.Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. This class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double.

Double class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static int MAX_EXPONENT : Maximum exponent a finite double variable may have.
  • static double MAX_VALUE :A constant holding the largest positive finite value of type double, (2-2-52)·21023.
  • static int MIN_EXPONENT :Minimum exponent a normalized double variable may have.
  • static double MIN_NORMAL :A constant holding the smallest positive normal value of type double, 2-1022.
  • static double MIN_VALUE :A constant holding the smallest positive nonzero value of type double, 2-1074.
  • static double NaN :A constant holding a Not-a-Number (NaN) value of type double.
  • static double NEGATIVE_INFINITY :A constant holding the negative infinity of type double.
  • static double POSITIVE_INFINITY :A constant holding the positive infinity of type double.
  • static int SIZE :The number of bits used to represent a double value.
  • static Class TYPE :The Class instance representing the primitive type double.

Constructors

  • Double(double value) :Constructs a newly allocated Double object that represents the primitive double argument.
  • Double(String s) :Constructs a newly allocated Double object that represents the floating-point value of type double represented by the string.

Methods

 

  • byte byteValue() :Returns the value of this Double as a byte (by casting to a byte).
  • static int compare(double d1, double d2) :Compares the two specified double values.
  • int compareTo(Double anotherDouble) :Compares two Double objects numerically.
  • static long doubleToLongBits(double value) :Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “double format” bit layout.
  • static long doubleToRawLongBits(double value) :Returns a representation of the specified floating-point value according to the IEEE 754 floating-point “double format” bit layout, preserving Not-a-Number (NaN) values.
  • double doubleValue() :Returns the double value of this Double object.
  • boolean equals(Object obj) :Compares this object against the specified object.
  • float floatValue() :Returns the float value of this Double object.
  • int hashCode() :Returns a hash code for this Double object.
  • int intValue() :Returns the value of this Double as an int (by casting to type int).
  • boolean isInfinite() :Returns true if this Double value is infinitely large in magnitude, false otherwise.
  • static boolean isInfinite(double v) :Returns true if the specified number is infinitely large in magnitude, false otherwise.
  • boolean isNaN() :Returns true if this Double value is a Not-a-Number (NaN), false otherwise.
  • static boolean isNaN(double v) :Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
  • double longBitsToDouble(long bits) :Returns the double value corresponding to a given bit representation.
  • long longValue() :Returns the value of this Double as a long (by casting to type long).
  • static double parseDouble(String s) :Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
  • short shortValue() :Returns the value of this Double as a short (by casting to a short).
  • static String toHexString(double d) Returns a hexadecimal string representation of the double argument.
  • String toString() :Returns a string representation of this Double object.
  • static String toString(double d) :Returns a string representation of the double argument.
  • static Double valueOf(double d) :Returns a Double instance representing the specified double value.
  • static Double valueOf(String s) :Returns a Double object holding the double value represented by the argument string s.

Exceptions

References

java.lang.Byte Class & Methods


The java.lang.Byte class wraps a value of primitive type byte in an object. An object of type Byte contains a single field whose type is byte. This class provides several utility methods like converting a byte to a String and a String to a byte, as well as other constants and methods useful when dealing with a byte.

Byte class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static byte MAX_VALUE :A constant holding the maximum value a byte can have, 27-1.
  • static byte MIN_VALUE :A constant holding the minimum value a byte can have, -27.
  • static int SIZE :The number of bits used to represent a byte value in two’s complement binary form.
  • static Class TYPE : The Class instance representing the primitive type byte.

Constructors

  • Byte(byte value):Constructs a newly allocated Byte object that represents the specified byte value.
  • Byte(String s) :Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Methods 

  • byte byteValue() :Returns the value of this Byte as a byte.
  • static int compare(byte x, byte y) :Compares two byte values numerically.
  • int compareTo(Byte anotherByte) :Compares two Byte objects numerically.
  • static Byte decode(String nm) :Decodes a String into a Byte.
  • double doubleValue() :Returns the value of this Byte as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Byte as a float.
  • int hashCode() :Returns a hash code for this Byte; equal to the result of invoking intValue().
  • int intValue() :Returns the value of this Byte as an int.
  • long longValue() :Returns the value of this Byte as a long.
  • static byte parseByte(String s) :Parses the string argument as a signed decimal byte.
  • static byte parseByte(String s, int radix) :Parses the string argument as a signed byte in the radix specified by the second argument.
  • short shortValue() :Returns the value of this Byte as a short.
  • String toString() :Returns a String object representing this Byte’s value.
  • static String toString(byte b) :Returns a new String object representing the specified byte.
  • static Byte valueOf(byte b) :Returns a Byte instance representing the specified byte value.
  • static Byte valueOf(String s) :Returns a Byte object holding the value given by the specified String.
  • static Byte valueOf(String s, int radix) :Returns a Byte object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References

Java : Immutable Class/Collection Creation


What is a Mutable/Immutable Class?

A class is called an immutable class once the object is created, we can not change it’s field/objects values. If values are changeable then it’s a mutable class.

Designing Rule

Classes should be immutable unless there’s a very good reason to make them mutable…
If a class cannot be made immutable, limit its mutability as much as possible.

In java all the wrapper classes and String class is immutable. For Ex: immutable classes like String, Boolean, Byte, Short, Integer, Long, Float, Double, etc.

How to make a class Immutable Class?

Below are step by step guide to making a class Immutable:

Step 1: Don’t provide “setter” methods that modify fields or objects referred to by fields.
Step 2: Make all fields final and private.
Step 3: Don’t allow subclasses to override methods. The simplest way to do this is to declare the class as final. A more sophisticated approach is to make the constructor private and construct instances in factory methods.
Step 4: If the instance fields include references to mutable objects, don’t allow those objects to be changed: Don’t provide methods that modify the mutable objects.
Step 5: Don’t share references to the mutable objects. Never store references to external, mutable objects passed to the constructor.
If necessary, create copies, and store references to the copies. Similarly, create copies of your internal mutable objects when necessary to avoid returning the originals in your methods.

What are the Benefits of Immutable Object?

  1. Immutable objects are thread-safe so you will not have any synchronization issues.
  2. Immutable objects are good Map keys and Set elements since these typically do not change once created.
  3. Immutability makes it easier to write, use and reason about the code (class invariant is established once and then unchanged)
  4. Immutability makes it easier to parallelize your program as there are no conflicts among objects.
  5. An immutable object’s internal state of your program will be consistent even if you have exceptions.
  6. References to immutable objects can be cached as they are not going to change.

How to create Immutable Lists, Sets or Maps?

JAVA 8 added the “unmodifiable” method and JAVA 9 added “of” factory method to make collections like lists, sets, and maps as immutable.  for example :

JAVA 8


Unmodifiable List
List stringList = Arrays.asList("Facing", "Issues", "On", "IT");
stringList = Collections.unmodifiableList(stringList);

Unmodifiable Set
Set stringSet = new HashSet<>(Arrays.asList("Facing", "Issues", "On", "IT"));
stringSet = Collections.unmodifiableSet(stringSet);

Unmodifiable Map
Map<String,Integer> stringMap = new HashMap<String, Integer>();
stringMap.put("Facing",1);
stringMap.put("Issues",2);
stringMap.put("On",3);
stringMap.put("IT",4);
stringMap = Collections.unmodifiableMap(stringMap);

JAVA 9


Unmodifiable List
List stringList = List.of("Facing", "Issues", "On", "IT");
Unmodifiable Set
Set stringSet = Set.of("Facing", "Issues", "On", "IT");

Unmodifiable Map
Map stringMap = Map.of("Facing",1, "Issues",2, "On",3, "IT",4);

Immutable Class Example


//make class final so that method not override
public final class ImmutableClass {
	final String pancardNumber;
	final String aadharNumber;
	final DOB dob;

	// Create object
	public ImmutableClass(String pancardNumber, String aadharNumber, DOB dob) {
		this.pancardNumber = pancardNumber;
		this.aadharNumber = aadharNumber;
		this.dob = dob;
	}
    //No setter method so that no fields get modifiable
	public String getPancardNumber() {
		return pancardNumber;
	}

	public String getAadharNumber() {
		return aadharNumber;
	}

	@Override
	public String toString() {
		return "ImmutableClass [pancardNumber=" + pancardNumber + ", aadharNumber=" + aadharNumber + ", dob=" + dob
				+ "]";
	}
}
public class  DOB {
	private int day;
	private int month;
	private int year;
	public DOB(int day, int month, int year)
	{
	this.day=day;
	this.month=month;
	this.year=year;
	}

	public int getDay() {
		return day;
	}

	public int getMonth() {
		return month;
	}

	public int getYear() {
		return year;
	}

	@Override
	public String toString() {
		return "DOB [day=" + day + ", month=" + month + ", year=" + year + "]";
	}

}
public class ImmuTableClassTest {

	public static void main(String[] args) {
		DOB dob = new DOB(24, 04, 1992);
		ImmutableClass immutableClass = new ImmutableClass("ABCD12345", "1234567890123456", dob);
		System.out.println(immutableClass);

	}

}

Output


ImmutableClass [pancardNumber=ABCD12345, aadharNumber=1234567890123456, dob=DOB [day=24, month=4, year=1992]]

Conclusion

In this blog you understand below points:

  • What is mutable and Immutable classes?
  • How make a class Immutable?
  • How to make collections like Lists, Sets, and maps  immutable by Java 8 and Java 9?
  • Immutable class example.

References

https://docs.oracle.com/javase/9/core/creating-immutable-lists-sets-and-maps.htm