1/69
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Primitive Data Types
Java provides 8 primitive data types (not created from classes).
Wrapper Class Definition
A class "wrapped around" a primitive data type to allow primitive values to be represented as objects.
Package Location
All wrapper classes are part of `java.lang` (no import statement required).
Immutability
Wrapper class objects are immutable; once created, their values cannot be changed.
Value Access
To retrieve the value stored inside a wrapper object, a method must be called (or unboxed).
`Character` Class Definition
Wraps a `char` data type in an object and provides static methods for testing, processing, and converting character data.
`Character.isDigit(char ch)`
Static method returning `true` if `ch` is a digit (0-9); otherwise returns `false`.
`Character.isLetter(char ch)`
Static method returning `true` if `ch` is an alphabetic letter; otherwise returns `false`.
`Character.isLetterOrDigit(char ch)`
Static method returning `true` if `ch` is a digit (0-9) or an alphabetic letter; otherwise returns `false`.
`Character.isLowerCase(char ch)`
Static method returning `true` if `ch` is a lowercase letter; otherwise returns `false`.
`Character.isUpperCase(char ch)`
Static method returning `true` if `ch` is an uppercase letter; otherwise returns `false`.
`Character.isSpaceChar(char ch)`
Static method returning `true` if `ch` is a space character; otherwise returns `false`.
`Character.isWhiteSpace(char ch)`
Static method returning `true` if `ch` is a whitespace character (space, tab, or newline); otherwise returns `false`.
`Character.toLowerCase(char ch)`
Static method returning the lowercase equivalent of `ch`.
`Character.toUpperCase(char ch)`
Static method returning the uppercase equivalent of `ch`.
Empty String
A string that has a length of 0 (contains no characters).
Blank String
A string that is either empty or contains only whitespace characters.
`isBlank()`
Returns `true` if the calling string is empty (length 0) or contains only whitespace characters.
`isEmpty()`
Returns `true` if the length of the calling string is 0.
Substring Definition
A string that is part of another string.
`contains(String str)`
Returns `true` if the calling string object contains the specified substring `str`.
`startsWith(String str)`
Determines whether a string begins with `str` (case-sensitive).
`endsWith(String str)`
Determines whether a string ends with `str` (case-sensitive).
`regionMatches(int start, String str, int start2, int n)`
Returns `true` if specified regions of two strings match (case-sensitive comparison).
`regionMatches(boolean ignoreCase, int start, String str, int start2, int n)`
Performs region match comparison; ignores case if `ignoreCase` is `true`.
`indexOf(char ch)`
Returns the position of the first occurrence of `ch` in the calling String, or `-1` if not found.
`indexOf(char ch, int start)`
Searches forward starting at index `start` for `ch`; returns index or `-1`.
`indexOf(String str)`
Returns the starting position of the first occurrence of `str`, or `-1` if not found.
`indexOf(String str, int start)`
Searches forward starting at index `start` for `str`; returns index or `-1`.
`lastIndexOf(char ch)`
Returns the position of the last occurrence of `ch`, or `-1` if not found.
`lastIndexOf(char ch, int start)`
Searches backward starting at index `start` to position 0 for `ch`; returns index or `-1`.
`lastIndexOf(String str)`
Returns the starting position of the last occurrence of `str`, or `-1` if not found.
`lastIndexOf(String str, int start)`
Searches backward starting at index `start` to position 0 for `str`; returns index or `-1`.
`substring(int start)`
Returns a new String containing characters from index `start` to the end of the string.
`substring(int start, int end)`
Returns a new String from index `start` up to (but not including) index `end`.
`getChars(...)`
Stores a substring from a String object into a destination `char` array.
`toCharArray()`
Returns the String object's contents converted into an array of `char` values.
`concat(String str)`
Returns a new String object that is the concatenation of the calling String and `str`.
`replace(char old, char new)`
Returns a String object with all occurrences of `old` character replaced by `new` character.
`indent(int n)`
Returns a copy of the String with line indentations adjusted (+n adds spaces, -n removes spaces, 0 leaves unchanged).
`repeat(int n)`
Returns a String object containing the contents of the calling String repeated `n` times.
`stripLeading()`
Returns a copy of the String object with all leading whitespace characters removed.
`stripTrailing()`
Returns a copy of the String object with all trailing whitespace characters removed.
`strip()`
Returns a copy of the String object with all leading and trailing whitespace characters removed.
Calling Methods on Literals
String class methods can be directly called on literal strings (e.g., `"*" .repeat(3)`).
`String.valueOf(...)`
Static overloaded methods that return a String representation of a primitive value or `char` array.
`StringBuilder` Definition
A mutable sequence of characters that can grow or shrink in size dynamically to accommodate changes.
`StringBuilder()` Constructor
Initializes object with enough storage space to hold 16 characters.
`StringBuilder(int length)` Constructor
Initializes object with enough storage space to hold `length` characters.
`StringBuilder(String str)` Constructor
Initializes object with text in `str` and enough space to hold `str`.
StringBuilder Shared Methods
Shares `charAt`, `getChars`, `indexOf`, `lastIndexOf`, `length`, and `substring` methods with `String`.
`append(item)`
Overloaded method that appends string representations of primitives, `char` arrays, or `String` objects/literals to the end.
`insert(int start, item)`
Overloaded method that inserts string representations of primitives, arrays, or objects beginning at position `start`.
`replace(int start, int end, String str)`
Replaces substring from `start` up to (excluding) `end` with `str`.
`deleteCharAt(int index)`
Deletes the single character at position `index`.
`delete(int start, int end)`
Deletes characters from position `start` up to (excluding) position `end`.
`setCharAt(int index, char ch)`
Changes the character at position `index` to `ch`.
`toString()`
Converts and returns a `StringBuilder` object to a regular `String` object.
Tokenizing Definition
The process of breaking a string down into individual components called tokens.
`split(String regex)`
Method in `String` class that tokenizes a String object and returns an array of String objects.
Primitive / Wrapper Mappings
`byte` $\rightarrow$ `Byte`, `double` $\rightarrow$ `Double`, `float` $\rightarrow$ `Float`, `int` $\rightarrow$ `Integer`, `long` $\rightarrow$ `Long`, `short` $\rightarrow$ `Short`.
Creating Wrapper Objects
Created via constructor (e.g., `new Integer(7)`) or primitive assignment (`Integer number = 7;`).
`toString(number)`
Static method in numeric wrappers that converts a numeric value to its String representation.
Base Conversion Methods
`Integer` and `Long` static methods: `toBinaryString`, `toHexString`, and `toOctalString`.
Parse Methods
Static methods (e.g., `parseInt`, `parseDouble`) that convert numeric String representations into primitive values.
`NumberFormatException`
Exception thrown by parse methods if the string argument does not represent a valid numeric value.
`MIN_VALUE` & `MAX_VALUE**` | Static final variables holding the minimum and maximum scalar values possible for a primitive type.
Autoboxing
Automatic conversion that Java performs between a primitive type and its corresponding object wrapper class.
Unboxing
Automatic conversion of a wrapper class object back to its corresponding primitive data type.
`ArrayList` Integration
Enables primitives to be used seamlessly in generic collections (e.g., `ArrayList