Chapter 3 Flashcards

1
Q

System.out.println(1 + 2 + “c”); ?

A

3c

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

String s1 = “1”;
String s2 = s1.concat(“2”);
s2.concat(“3”);
System.out.println(s2);

?

A

12

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

String pool or intern pool is what?

A

A location in the JVM that collects reusable strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
Which is less efficient. Why?
String name = "Fluffy";
String name = new String("Fluffy");
A

new keyword is less efficient as string pool is not used. Here fluffy is not a literal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
How do these string methods work?
length()
charAt()
indexOf()
substring()
A

string. length();
string. charAt(5);
string. indexOf(char, index);
string. substring(begin, end);
string. substring(begin);

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

write these string methods:
startsWith()
endsWith
equals

A

“abc”.startsWith(“a”) // true
“Abc”.endsWith(“c”) // true
“Abc”.equals(“abc”) // false

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

String methods:
replace()
contains()

A

“abcabc”.replace(‘a’, ‘A’);
“abcabc”.replace(“a”, “A”);
“Abc”.contains(“b”);

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

Stringbuilder, immutable or mutable? And String?

A

Mutable, i.e. Changeable.

String however is immutable, unchangeable.

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

Logical equality vs object equality for strings?

A

== is object/reference equality
.equals is logical equality
Strings have special equals method, usually .equals checks reference equality.

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

Which is which? parseBoolean(“true”) valueOf(“TRUE”)

A

First converts string to primitive. Second string to wrapper class.

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

Which wrapper class constructors need casts?

A
new Byte((byte) 1)
new Short((short) 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a fixed size list or backed list?

A

An array changed into a basic List (not an ArrayList). Using set() on this List updates both array and list.
List list = Arrays.asList(array)

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

Sort an array?

Sort an ArrayList?

A

Arrays.sort(array);

Collections.sort(arraylist);

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

What are the three time classes? Do they have constructors?

A

LocalTime, LocalDate, LocalDateTime.
No, example:
LocalTime time = LocalTime.of(6,15);

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

Is LocalDate mutable or immutable?

A

Immutable. Therefore must assign to reference when manipulating it.

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