review Flashcards
(49 cards)
What is the default value of a boolean?
false
What is the default value of an int?
0
What does Math.random() return?
A double between 0.0 (inclusive) and 1.0 (exclusive)
How do you generate an int from 1 to 10 using Math.random()?
(int)(Math.random() * 10) + 1
What does == do for primitives?
Compares values
What does == do for objects?
Compares references (not content)
How do you compare strings?
Using .equals()
What does .equalsIgnoreCase() do?
Compares strings ignoring upper/lower case
How do you convert String to int?
Integer.parseInt(str)
How do you convert String to double?
Double.parseDouble(str)
How do you convert int to String?
Integer.toString(num)
What does charAt(i) return?
The character at index i in a string
What is string concatenation?
Joining strings with +
What is substring(a
b)?
What is substring(a)?
Extracts characters from index a to the end
What does indexOf(char) do?
Returns the first index of a character
What is a wrapper class?
An object version of a primitive (e.g.
Can ArrayLists hold primitive types?
No
What is the difference between Array and ArrayList?
Array has fixed size
What method returns ArrayList size?
list.size()
What method adds an item to an ArrayList?
list.add(item)
How do you loop through an ArrayList?
Use for loop or enhanced for loop
What does list.remove(index) do?
Removes the item at the given index
What does list.contains(item) do?
Returns true if item is found