chapter 7 (so far) Flashcards

(48 cards)

1
Q

What is a string

A

-A String is a class
-Each created String is a class object
The String variable name is not a simple data type
-Holds the memory address of a string and is immutable

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

Reference

A

A variable that holds a memory address

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

What does the == operator do regarding strings

A

it compares the memory locations of the strings rather than their values
-Compares constants of the memory locations more frequently than memory locations themselves

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

What class to use for character

A
  • Char/ Character
  • holds a single character value
  • defines methods that can manipulate or inspect single-character data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What class to use for working with fixed string data and unchanging data composed of multiple characters

A

string

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

What are StringBuilder and StringBuffer

A

Classes for storing and manipulating changeable data composed of multiple character

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

Describe the character class’ methods

A

Methods that begin with “is” such as isUpperCase() return a boolean value that can be used in comparison statements
Methods that begin with “to” such as toUpperCase() return a character that have been converted to the stated format

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

literal string

A

A sequence of characters enclosed within double quotation marks
An unnamed object, or anonymous object, of the String class

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

String variable

A

A named object of the String class

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

Class String

A

Defined in java.lang.String

Automatically imported into every program

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

What is the relation between the string and variable assigned to it

A

the string itself is distinct from the variable used to refer to it

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

string variable name

A

a reference to a variable

refers to a location in memory rather than a particular variable

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

What happens when a new value is given to a string

A

the address held by the string is altered

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

immutable

A

unchanging objects such as strings
this means making simple comparisons between strings produces sometimes misleading results
-Compares memory addresses, not values

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

equals() method

A

Evaluates the contents of two String objects to determine if they are equivalent
Returns true if objects have identical contents
public boolean equals(String s)

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

equalsIgnoreCase() method

A

Ignores case when determining if two Strings are equivalent

Useful when users type responses to prompts in programs

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

compareTo() method

A

Compares two Strings and returns:
-Zero: If two Strings refer to the same value
-Negative number: If the calling object is “less than” the argument
-Positive number: If the calling object is “more than” the argument
if (aWord.compareTo(anotherWord) < 0)

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

What is an empty string

A

Reference a memory address with no characters

Can be used in String methods

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

null string

A
  • Use the null Java keyword
  • Strings are set to null by default
  • Cannot be used in String methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

toUpperCase() and toLowerCase()

A

Convert any String to its uppercase or lowercase equivalent

21
Q

length()

A

Returns the length of a String

22
Q

indexOf() method

A

Determines whether a specific character occurs within a String
Returns the position of the character
The first position of a String is zero
The return value is –1 if the character does not exist in the String

23
Q

charAt() method

A

Requires an integer argument

Indicates the position of the character that the method returns

24
Q

endsWith() method and startsWith()

A
  • Each takes a String argument

- Return true or false if a String object does or does not end or start with the specified argument, respectively

25
replace()
Replaces all occurrences of some character within a String
26
toString()
``` Not part of the String class Converts any object to a String Converts primitive data types to Strings String theString; int someInt = 4; theString = Integer.toString(someInt); ```
27
Concatenation
Join a simple variable to a String String aString = "My age is " + myAge; Use the + operator
28
substring()
``` Extracts part of a String Takes two integer arguments -Start position -End position The length of the extracted substring is the difference between the second integer and the first integer ```
29
regionMatches()
Two variants that can be used to test if two String regions are equal
30
when is A substring of the specified String object is compared to a substring of the other
If the substrings contain the same character sequence, then the expression is true Otherwise, the expression is false A second version uses an additional boolean argument Determines whether case is ignored when comparing characters
31
Integer class
``` Part of java.lang Automatically imported into programs Converts a String to an integer parseInt() method Takes a String argument Returns its integer value ```
32
Wrapper
A class or an object “wrapped around” a simpler element
33
Integer class valueOf() method
Part of java.lang Automatically imported into programs Converts a String to an integer
34
parseInt() method
Takes a String argument | Returns its integer value
35
Wrapper
A class or an object “wrapped around” a simpler element
36
Integer class intValue() method
Extracts the simple integer from its wrapper class
37
Double class
``` A wrapper class Imported into programs automatically parseDouble() method Takes a String argument and returns its double value ```
38
StringBuilder and StringBuffer classes
``` An alternative to the String class Used when a String will be modified Can use anywhere you would use a String Part of the java.lang package Automatically imported into every program ```
39
Compare StringBuilder and StringBuffer
StringBuilder is more efficient | StringBuffer is thread safe and used in multithreaded programs
40
Buffer
A memory block Might or might not contain a String The String might not occupy the entire buffer The length of a String can be different from -the length of the buffer Capacity -The actual length of the buffer
41
setLength() method
Changes the length of a String in a StringBuilder object
42
length property
``` An attribute of the StringBuilder class Identifies the number of characters in the String contained in the StringBuilder ```
43
capacity() method
Finds the capacity of a StringBuilder object
44
What do StringBuilder objects do
Provides improved computer performance over String objects | Can insert or append new contents into StringBuilder
45
append() method
Adds characters to the end of a StringBuilder object
46
insert() method
Adds characters at a specific location within a StringBuilder object
47
setCharAt() method
Changes a character at a specified position within a StringBuilder object
48
charAt() method
Accepts an argument that is the offset of the character position from the beginning of a String Returns the character at that position