CS122 Flashcards

1
Q

What does nextInt(max) do?

A

Returns a random integer from 0 to max-1.

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

What does nextDouble() do?

A

Returns a random real number between 0.0 to 1.0.

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

What does contains(str) do?

A

Returns true if this string contains str inside.

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

What does endsWith(str) do?

A

Returns true if this string ends with str.

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

What does startsWith(str) do?

A

Returns true if this string starts with str.

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

What does equals(str) do?

A

Returns true if this string is the same as str.

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

What does equalsIgnoreCase(str) do?

A

Returns true if this string is the same as str, ignoring capitalization.

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

What does indexOf(str) do?

A

Returns the index in this string where given str begins (-1 if not found).

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

What does length() do?

A

Returns the number of characters in this string.

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

What does substring(i,j) do?

A

Returns characters in this string from index i (inclusive) to index j (exclusive).

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

What does toLowerCase() do?

A

Returns a new string with all lowercase characters.

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

What does toUpperCase() do?

A

Returns a new string with all uppercase characters.

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

What does charAt(i) do?

A

Returns the character at index i.

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

What does add(index, value) do in List<E>?</E>

A

Inserts given value at given index, shifting subsequent values right.

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

What does add(value) do in List<E>?</E>

A

Inserts given value at the end of the list.

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

What does contains(value) do in List<E>?</E>

A

Returns true if the given value is found, false otherwise.

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

What does indexOf(value) do in List<E>?</E>

A

Returns the first index where given value is found in the list (-1 if not found).

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

What does get(index) do in List<E>?</E>

A

Returns the value at given index.

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

What does remove(value) do in List<E>?</E>

A

Removes/returns value at given index, shifting subsequent values left.

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

What does set(index, value) do in List<E>?</E>

A

Replaces value at given index with given value.

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

What does peek() do in Stack<E>?</E>

A

Returns the top value from the stack without removing it.

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

What does pop() do in Stack<E>?</E>

A

Removes the top value from the stack and returns it.

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

What does push(value) do in Stack<E>?</E>

A

Places the given value on top of the stack.

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

What does size() do in Stack<E>?</E>

A

Returns the number of elements in the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does isEmpty() do in Stack?
Returns true if stack has no elements.
26
What does add(value) do in Queue?
Places the given value at the back of the queue.
27
What does peek() do in Queue?
Returns the front value from the queue without removing it.
28
What does remove() do in Queue?
Removes the value from the front of the queue and returns it.
29
What does size() do in Queue?
Returns the number of elements in the queue.
30
What does isEmpty() do in Queue?
Returns true if queue has no elements.
31
What does containsKey(key) do in Map?
Returns true if the map contains a mapping for the given key.
32
What does get(key) do in Map?
Returns the value mapped to the given key (null if none).
33
What does keySet() do in Map?
Returns a Set of all keys in the map.
34
What does put(key, value) do in Map?
Adds a mapping from the given key to the given value.
35
What does putAll(map) do in Map?
Adds all key/value pairs from the given map to this map.
36
What does remove(key) do in Map?
Removes any existing mapping for the given key.
37
What does toString() do in Map?
Returns a string such as “{a=90, b=30, c=29}”.
38
What does values() do in Map?
Returns a Collection of all values in the map.
39
How do you declare a List of Integers?
List list = new ArrayList();
40
How do you declare a Stack of Integers?
Stack s = new Stack();
41
How do you declare a Queue of Integers?
Queue q = new LinkedList();
42
How do you declare a Set of Strings?
Set words = new HashSet();
43
How do you declare a Map of Strings to Integers?
Map counts = new TreeMap();
44
What is the purpose of the method isConsecutive?
The method isConsecutive checks if a stack of integers contains a sequence of consecutive integers starting from the bottom of the stack.
45
What should isConsecutive return for the stack [3, 4, 5, 6, 7, 8, 9, 10]?
It should return true.
46
What should isConsecutive return for the stack [3, 4, 5, 6, 7, 8, 9, 10, 12]?
It should return false.
47
What should isConsecutive return for the stack [3, 2, 1]?
It should return false.
48
What is the behavior of the method removeShorterStrings?
The method removes the shorter string from each successive pair in an ArrayList of Strings.
49
What happens if there is a tie in removeShorterStrings?
The first string in the pair is removed.
50
What does the method minToFront do?
The method moves the minimum value in an ArrayList of integers to the front while preserving the order of the elements.
51
What is the output of minToFront for the list {3, 8, 92, 4, 2, 17, 9}?
The output should be {2, 3, 8, 92, 4, 17, 9}.
52
What is the purpose of the compareTo method in the Point class?
The compareTo method allows Points to be compared based on their distance from the origin.
53
What does the method removeInRange do?
The method removes all occurrences of a specified element in an ArrayList between a starting and ending index.
54
What is the output of removeInRange for the list [0, 0, 2, 0, 4, 0, 6, 0, 8, 0, 10, 0, 12, 0, 14, 0, 16] with parameters (0, 5, 13)?
The output should be [0, 0, 2, 0, 4, 6, 8, 10, 12, 0, 14, 0, 16].
55
What does the method stutter do?
The method replaces every string in an ArrayList with k copies of that string.
56
What happens if k is 0 or negative in the stutter method?
The list should be empty after the call.
57
What is the purpose of the method removeDuplicates?
The method eliminates duplicates from a sorted ArrayList of Strings.
58
What is the output of removeDuplicates for the list {"be", "be", "is", "not", "or", "question", "that", "the", "to", "to"}?
The output should be {"be", "is", "not", "or", "question", "that", "the", "to"}.
59
What does the method collectionMystery1 do?
The method processes a HashMap and prints a new HashMap based on the comparison of keys and values.
60
What is the output of collectionMystery1 for the map {skate=board, drive=car, program=computer, play=computer}?
The output will be {drive=car, skate=board, program=computer, play=computer}.
61
What does the method search return?
The method returns a set with the most frequent strings from a given string list.
62
What is the output of search for the list ["a", "b", "cd", "cd", "ef", "ef"]?
The output will be a set containing ["cd", "ef"].
63
What does the method that accepts a List of Strings and a Set of Characters do?
It determines the number of times each character is found in the words as a map.
64
What is the output for the set ('b','o') and the List ("book", "love", "born")?
It would return a map {'b' = 2, 'o' = 4}.