Java Reference Methods Flashcards
1
Q
equals method
A
defined in object, takes in an object and compares is
2
Q
“hello”.substring( 3)
A
gives “lo” as h is zero, e is 1, and so on until the second l is 3.
3
Q
“A”.compareTo(“B”)
“A”.compareTo(“a”)
A
both are negative, a before b, and capitals before lowercase.
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");
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.
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