1/24
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
String (Java)
An object representing a sequence of characters (letters, digits, punctuation, spaces); variables of type String store a reference to a String object.
Immutable (String immutability)
A property meaning a String cannot be changed after it’s created; any “modification” method produces a new String object.
String literal
A String value written directly in code using quotes, e.g., "Ava" or "".
Concatenation
Joining strings together, commonly using the + operator (e.g., "Hello, " + name).
String conversion (with +)
When one operand of + is a String, Java converts the other operand to a String and concatenates.
Evaluation order pitfall (String + numbers)
Once concatenation with a String starts, later + operations concatenate as text unless parentheses force arithmetic ("Sum: " + 2 + 3 → "Sum: 23").
length()
A String instance method that returns the number of characters in the string (counts spaces/punctuation too).
Valid String indices
For a String of length n, the valid character indices are 0 through n − 1.
Off-by-one error
A common indexing mistake where code uses an index one too high/low (often forgetting indices stop at length() − 1 or end index is exclusive).
substring(int from, int to)
Returns a new String slice starting at index from (inclusive) and stopping before index to (exclusive).
substring(int from)
Returns a new String from index from (inclusive) to the end of the original string.
Exclusive end index (substring)
In substring(from, to), the character at index to is NOT included; to is the first index not taken.
StringIndexOutOfBoundsException
A runtime error that occurs when substring/char indexing uses an index outside 0..length() (or violates from/to rules).
indexOf(String str)
A String method that returns the index of the first occurrence of str, or -1 if not found.
indexOf(String str, int fromIndex)
An overloaded indexOf that begins searching at fromIndex; returns first match at/after that position, or -1 if not found.
Sentinel value -1 (indexOf)
The value returned by indexOf when the search string is not found; must be checked before using the result as an index.
equals(String other)
A String method that returns true if two strings have the same characters in the same order (content comparison).
== vs equals (Strings)
== compares references (same object); equals compares contents (same characters).
compareTo(String other)
Compares strings in lexicographic (dictionary) order; returns
Lexicographic order (case sensitivity)
Ordering based on character codes; uppercase letters typically come before lowercase, affecting compareTo results.
Static method
A method called using the class name (not an instance), e.g., Math.sqrt(81); you do not create an object to use it.
Math.abs(x)
A static Math method that returns the absolute value of x (distance from 0).
Math.pow(a, b)
A static Math method that returns a^b as a double (even if inputs look like integers).
Math.random()
A static Math method that returns a pseudorandom double in the range [0.0, 1.0) (0.0 inclusive, 1.0 exclusive).
Random integer range formula
To get an int from min to max inclusive: (int)(Math.random() * (max - min + 1)) + min (cast after scaling).