Character and string Methods Flashcards

(81 cards)

1
Q

A ___________ is not a simple data type but a reference—it holds a memory address, not the actual
value.

A

String variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A String variable is _____________ but a reference—it holds a memory address, not the actual
value.

A

not a simple data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A String variable is not a simple data type but a _________—it holds a memory address, not the actual
value.

A

reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A String variable is not a simple data type but a reference—it holds a _____________, not the___________.

A

memory address
actual value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When you use __ to compare two
Strings, you’re comparing their _____________, not their ________.

A

==
memory addresses
actual values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

_________ usually want to compare the values
of Strings, not their memory addresses.

A

Programmers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Programmers usually want to compare the ___________, not their___________.

A

values of Strings
memory addresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

______________:
Holds a single character

A

Character Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Character Class:
Holds a _________

A

single character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

______________:
Provides methods to manipulate and inspect
single-character data.

A

Character Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Character Class:
Holds a single character (e.g., ‘A’, ‘8’, ‘$’).
Provides methods to ________ and ______________.

A

manipulate
inspect single-character data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

___________:
Used for fixed (unchanging) text data made
up of one or more characters.
Offers many methods to simplify working with
Strings.

A

String Class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

String Class:
Used for_______________ made
up of _______________.
Offers many methods to simplify working with
Strings.

A

fixed (unchanging) text data
one or more characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The _____________:
Used to store a single character, such as a
letter, digit, or punctuation mark.

A

char Data Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The char Data Type:
Used to _____________, such as a
letter, digit, or punctuation mark.

A

store a single character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The char Data Type:
Used to store a single character, such as a
_______,________, or_____________.

A

letter
digit
punctuation mark

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

char literals are written inside_______________

A

single quotation
marks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Since char is a _____________, it holds
actual values (not memory addresses).

A

primitive data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Since char is a primitive data type, it holds
___________ (_________).

A

actual values
not memory addresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

You can compare char values using _______________ like == and >.

A

relational operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Comparisons are based on the ________ value of
each character.

A

Unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

These comparisons work as you’d expect—
_____________.

A

alphabetically

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Java also provides a _________ for working
with characters.

A

Character class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

This class includes useful methods for_______ and
__________ character values.

A

testing
manipulating

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
This __________ includes useful methods for testing and manipulating character values.
class
26
The ____________ is part of the____________, which is automatically imported into every Java program.
Character class java.lang package
27
Checks if the given character is a letter (uppercase or lowercase).
isLetter(char ch)
28
Checks if the given character is a digit
isDigit(char ch)
29
Checks if the given character is a whitespace (space, tab, newline, etc.).
isWhitespace(char ch)
30
Converts the given character to its uppercase equivalent.
toUpperCase(char ch)
31
Converts the given character to its lowercase equivalent.
toLowerCase(char ch)
32
Checks if the given character is an uppercase letter.
isUpperCase(char ch)
33
Checks if the given character is a lowercase letter.
isLowerCase(char ch)
34
Converts the given character to a String.
toString(char ch)
35
Checks if the given character is a letter or a digit.
isLetterOrDigit(char ch)
36
Compares two characters numerically based on their Unicode values.
compare(char x, char y)
37
Compares two characters numerically based on their _______________.
Unicode values
38
_____________ are one of the most common dataType in Java.
Strings
39
Strings are one of the most common ______ in Java.
dataType
40
Primitive Types (e.g., int): When you declare int x = 10;, the __________ of x holds the value 10. If you update x to 45, the _____ replaces the old one at the same memory address.
memory address new value
41
When you declare String aGreeting = "Hello";, aGreeting holds the ____________ of the String "Hello", not the ________.
memory address actual characters
42
You cannot choose _________; they are assigned by the __________.
memory addresses operating system
43
Strings are ____________they are never changed. Instead, new Strings are created, and references are updated to point to the new memory addresses.
immutable
44
Strings are immutable—they are never changed. Instead, ________ are created, and _________ are updated to point to the ______________.
new Strings references new memory addresses
45
Comparing Strings with < or > will cause a ________________. These operators cannot be used with Strings.
compilation error
46
Use the + operator to combine (concatenate) Strings.
Concatenating Strings
47
Created using double quotes with no characters inside.
Empty Strings
48
Refers to a memory address where no characters are stored.
Empty String
49
Refers to a_________ where _________ are stored. Can be used with String methods like ________.
memory address no characters .equals()
50
_________: Created by assigning null to a String.
Null Strings
51
A _________ does not reference any memory address.
null String
52
Cannot be used with String methods like___________ —it will cause an error.
.equals()
53
Others find it ________ since unassigned Strings are null by default.
redundant
54
Returns the number of characters in a String.
length()
55
Finds the position of a character or substring in a String.
indexOf()
56
Returns the character at a specific position.
charAt()
57
Extracts part of a String.
substring()
58
The __________ method takes_______________—a start position and an end position—that are both based on the fact that a String’s first position is position zero.
substring() two integer arguments
59
The_________________ is the difference between the second integer and the first integer; if you call the method without a second integer argument, the substring extends to the end of the original string.
length of the extracted substring
60
The length of the extracted substring is the difference between the _________________; if you call the method without a second integer argument, the substring extends to the end of the original string.
second integer and the first integer
61
Checks if a String starts with a specific substring.
startsWith()
62
Checks if a String ends with a specific substring
endsWith()
63
Replaces all occurrences of a character or String/substring.
replace()
64
Checks if a String contains a specific substring.
contains()
65
Converts current dataType to a String (implicitly used in print() and println()).
toString()
66
Finds the position of a substring starting from a specific index.
indexOf(String, int)
67
Checks if a String is empty or contains only whitespace.
isBlank()
68
Checks if a String has no characters.
isEmpty()
69
Converts the String to lowercase.
toLowerCase()
70
Converts the String to uppercase.
toUpperCase()
71
Removes leading and trailing whitespace.
strip()
72
Removes leading and trailing whitespace (similar to strip() but available in older Java versions).
trim()
73
Why Convert Strings to Numbers?
perform arithmetic operations.
74
It provides the _______________ method, which takes a String and returns its integer value.
parseInt()
75
parseInt() is a static method, so you call it using the class name (___________).
Integer.parseInt()
76
It provides the ___________method, which takes a String and returns its double values.
parseDouble()
77
indexOf(): Finds the position of a character or substring in a String. Returns ______ if not found.
-1
78
Converts a String to a float.
Float.parseFloat():
79
Converts a String to a long.
Long.parseLong()
80
Forgetting to handle null Strings, leading to ____________.
runtime errors
81
Misusing methods like charAt() with invalid positions (causing ______________________).
StringIndexOutOfBoundsException