Strings Flashcards

(12 cards)

1
Q

What is a stack?

A
  • Stores local variables
  • Stores addresses to objects in the heap
  • Follows the last in, last out order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a heap?

A
  • Stores all objects
  • Stores instance variables in objects
  • Has a String Pool
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Two strings store the same message. Is memory used twice?

A

No. The second string will refer to the first string.

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

What is the difference here?
String str1 = “Hello”;
String str2 = “Hello”;
String str3 = new String(“Hello”);

A

String str3 will not have the same reference as str1 or str2.

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

What does name.equals(object another) do?

A

Returns true or false if the strings match

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

What does name.charAt(int index) do?

A

Returns the character at the index

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

What does name.compareTo(String another) do?

A

Compares two strings with <, >, and =.

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

How can we use backslashes, quotation marks, line breaks, and tabs within strings?

A
  • \
  • "
  • \n
  • \t
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Compare the values based on their Unicode index.
a and b
A and a
Cart and Car
Car and Cart

A

a < b
A < a
Car = Car
Car < Cart

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

How do you convert an int to String?

A

String.valueOf(int)

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

How do you convert a String to int?

A

Integer.parseInt(“stringOfNumbers”)

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

What is the format for most math functions?

A

Math.functionName(neededVariables)

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