Java Reference Methods Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

equals method

A

defined in object, takes in an object and compares is

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

“hello”.substring( 3)

A

gives “lo” as h is zero, e is 1, and so on until the second l is 3.

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

“A”.compareTo(“B”)

“A”.compareTo(“a”)

A

both are negative, a before b, and capitals before lowercase.

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

Replace an element in an array list

A
ArrayList: E set(index, E value)
returns the value being replaced
ArrayList list = new ArrayList();
list.add("Hello");
String hello = list.set(0, "Goodbye");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
ArrayList numlist = new ArrayList();
list.add("Hello");

Does this give you a) no error, b) a compile time error c) a runtime error?

A

Compile time error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
ArrayList untyped = new ArrayList()
untyped.add(new Integer(1));
untyped.add("Hello");
ArrayList stringList = (ArrayList)untyped;
String firstString = stringList.get(0);

Does this give you a) no error, b) a compile time error c) a runtime error?

A

runtime error

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