Java String and Wrapper Class: Methods, Immutability, and Data Types

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/69

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:43 PM on 7/23/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

70 Terms

1
New cards

Primitive Data Types

Java provides 8 primitive data types (not created from classes).

2
New cards

Wrapper Class Definition

A class "wrapped around" a primitive data type to allow primitive values to be represented as objects.

3
New cards

Package Location

All wrapper classes are part of `java.lang` (no import statement required).

4
New cards

Immutability

Wrapper class objects are immutable; once created, their values cannot be changed.

5
New cards

Value Access

To retrieve the value stored inside a wrapper object, a method must be called (or unboxed).

6
New cards

`Character` Class Definition

Wraps a `char` data type in an object and provides static methods for testing, processing, and converting character data.

7
New cards

`Character.isDigit(char ch)`

Static method returning `true` if `ch` is a digit (0-9); otherwise returns `false`.

8
New cards

`Character.isLetter(char ch)`

Static method returning `true` if `ch` is an alphabetic letter; otherwise returns `false`.

9
New cards

`Character.isLetterOrDigit(char ch)`

Static method returning `true` if `ch` is a digit (0-9) or an alphabetic letter; otherwise returns `false`.

10
New cards

`Character.isLowerCase(char ch)`

Static method returning `true` if `ch` is a lowercase letter; otherwise returns `false`.

11
New cards

`Character.isUpperCase(char ch)`

Static method returning `true` if `ch` is an uppercase letter; otherwise returns `false`.

12
New cards

`Character.isSpaceChar(char ch)`

Static method returning `true` if `ch` is a space character; otherwise returns `false`.

13
New cards

`Character.isWhiteSpace(char ch)`

Static method returning `true` if `ch` is a whitespace character (space, tab, or newline); otherwise returns `false`.

14
New cards

`Character.toLowerCase(char ch)`

Static method returning the lowercase equivalent of `ch`.

15
New cards

`Character.toUpperCase(char ch)`

Static method returning the uppercase equivalent of `ch`.

16
New cards

Empty String

A string that has a length of 0 (contains no characters).

17
New cards

Blank String

A string that is either empty or contains only whitespace characters.

18
New cards

`isBlank()`

Returns `true` if the calling string is empty (length 0) or contains only whitespace characters.

19
New cards

`isEmpty()`

Returns `true` if the length of the calling string is 0.

20
New cards

Substring Definition

A string that is part of another string.

21
New cards

`contains(String str)`

Returns `true` if the calling string object contains the specified substring `str`.

22
New cards

`startsWith(String str)`

Determines whether a string begins with `str` (case-sensitive).

23
New cards

`endsWith(String str)`

Determines whether a string ends with `str` (case-sensitive).

24
New cards

`regionMatches(int start, String str, int start2, int n)`

Returns `true` if specified regions of two strings match (case-sensitive comparison).

25
New cards

`regionMatches(boolean ignoreCase, int start, String str, int start2, int n)`

Performs region match comparison; ignores case if `ignoreCase` is `true`.

26
New cards

`indexOf(char ch)`

Returns the position of the first occurrence of `ch` in the calling String, or `-1` if not found.

27
New cards

`indexOf(char ch, int start)`

Searches forward starting at index `start` for `ch`; returns index or `-1`.

28
New cards

`indexOf(String str)`

Returns the starting position of the first occurrence of `str`, or `-1` if not found.

29
New cards

`indexOf(String str, int start)`

Searches forward starting at index `start` for `str`; returns index or `-1`.

30
New cards

`lastIndexOf(char ch)`

Returns the position of the last occurrence of `ch`, or `-1` if not found.

31
New cards

`lastIndexOf(char ch, int start)`

Searches backward starting at index `start` to position 0 for `ch`; returns index or `-1`.

32
New cards

`lastIndexOf(String str)`

Returns the starting position of the last occurrence of `str`, or `-1` if not found.

33
New cards

`lastIndexOf(String str, int start)`

Searches backward starting at index `start` to position 0 for `str`; returns index or `-1`.

34
New cards

`substring(int start)`

Returns a new String containing characters from index `start` to the end of the string.

35
New cards

`substring(int start, int end)`

Returns a new String from index `start` up to (but not including) index `end`.

36
New cards

`getChars(...)`

Stores a substring from a String object into a destination `char` array.

37
New cards

`toCharArray()`

Returns the String object's contents converted into an array of `char` values.

38
New cards

`concat(String str)`

Returns a new String object that is the concatenation of the calling String and `str`.

39
New cards

`replace(char old, char new)`

Returns a String object with all occurrences of `old` character replaced by `new` character.

40
New cards

`indent(int n)`

Returns a copy of the String with line indentations adjusted (+n adds spaces, -n removes spaces, 0 leaves unchanged).

41
New cards

`repeat(int n)`

Returns a String object containing the contents of the calling String repeated `n` times.

42
New cards

`stripLeading()`

Returns a copy of the String object with all leading whitespace characters removed.

43
New cards

`stripTrailing()`

Returns a copy of the String object with all trailing whitespace characters removed.

44
New cards

`strip()`

Returns a copy of the String object with all leading and trailing whitespace characters removed.

45
New cards

Calling Methods on Literals

String class methods can be directly called on literal strings (e.g., `"*" .repeat(3)`).

46
New cards

`String.valueOf(...)`

Static overloaded methods that return a String representation of a primitive value or `char` array.

47
New cards

`StringBuilder` Definition

A mutable sequence of characters that can grow or shrink in size dynamically to accommodate changes.

48
New cards

`StringBuilder()` Constructor

Initializes object with enough storage space to hold 16 characters.

49
New cards

`StringBuilder(int length)` Constructor

Initializes object with enough storage space to hold `length` characters.

50
New cards

`StringBuilder(String str)` Constructor

Initializes object with text in `str` and enough space to hold `str`.

51
New cards

StringBuilder Shared Methods

Shares `charAt`, `getChars`, `indexOf`, `lastIndexOf`, `length`, and `substring` methods with `String`.

52
New cards

`append(item)`

Overloaded method that appends string representations of primitives, `char` arrays, or `String` objects/literals to the end.

53
New cards

`insert(int start, item)`

Overloaded method that inserts string representations of primitives, arrays, or objects beginning at position `start`.

54
New cards

`replace(int start, int end, String str)`

Replaces substring from `start` up to (excluding) `end` with `str`.

55
New cards

`deleteCharAt(int index)`

Deletes the single character at position `index`.

56
New cards

`delete(int start, int end)`

Deletes characters from position `start` up to (excluding) position `end`.

57
New cards

`setCharAt(int index, char ch)`

Changes the character at position `index` to `ch`.

58
New cards

`toString()`

Converts and returns a `StringBuilder` object to a regular `String` object.

59
New cards

Tokenizing Definition

The process of breaking a string down into individual components called tokens.

60
New cards

`split(String regex)`

Method in `String` class that tokenizes a String object and returns an array of String objects.

61
New cards

Primitive / Wrapper Mappings

`byte` $\rightarrow$ `Byte`, `double` $\rightarrow$ `Double`, `float` $\rightarrow$ `Float`, `int` $\rightarrow$ `Integer`, `long` $\rightarrow$ `Long`, `short` $\rightarrow$ `Short`.

62
New cards

Creating Wrapper Objects

Created via constructor (e.g., `new Integer(7)`) or primitive assignment (`Integer number = 7;`).

63
New cards

`toString(number)`

Static method in numeric wrappers that converts a numeric value to its String representation.

64
New cards

Base Conversion Methods

`Integer` and `Long` static methods: `toBinaryString`, `toHexString`, and `toOctalString`.

65
New cards

Parse Methods

Static methods (e.g., `parseInt`, `parseDouble`) that convert numeric String representations into primitive values.

66
New cards

`NumberFormatException`

Exception thrown by parse methods if the string argument does not represent a valid numeric value.

67
New cards

`MIN_VALUE` & `MAX_VALUE**` | Static final variables holding the minimum and maximum scalar values possible for a primitive type.

68
New cards

Autoboxing

Automatic conversion that Java performs between a primitive type and its corresponding object wrapper class.

69
New cards

Unboxing

Automatic conversion of a wrapper class object back to its corresponding primitive data type.

70
New cards

`ArrayList` Integration

Enables primitives to be used seamlessly in generic collections (e.g., `ArrayList`) where primitives are disallowed.