Chapter 3 Flashcards

1
Q

What does API stand for?

A

application programming interfaces that give you access to a service or functionality

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

What is string concatenation?

A

Placing one String before another String and combining them

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

what does the + mean here: “a” + “b”

A

concatenation

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

What is the order of evaluation with addition and concatenation?

A

evaluated left to right

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

What is the output of the following: sys out(1+3); sys out(“a”+”b”); sys out(“a”+”b”+3; sys out(1+2+”c”);

A

4 ab ab3 3c

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

What is the output and type of the sysout: int three = 3; String four = “4”; sysout(1+2+three+four):

A

string 64

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

What does += do in the context of Strings? (What does s+=”2 mean?)

A

s = s + “2”;

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

What is the output? String s = “1”; s +=”2”; s +=”3”; sysout(s)

A

s is equal to “123”;

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

What doe sit mean to say that Strings are immutable?

A

They are not allowed to change. It cannot be made larger or smaller and you can’t change one of the letters inside of it. Nothing about it can change!

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

What is the output? String s1 = “1”; String s2 = s1.concat(“2”); s2.concat(“3”); System.out.println(s2);

A
  1. s2.concat 3 would need to be stored in a new variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the output? String s1 = “1”; String s2 = s1.concat(“2”); s2.concat(“3”); System.out.println(s2);

A
  1. s2.concat 3 would need to be stored in a new variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does Java do because it realizes Strings take up a lot of memory?

A

It is able to recognize when one String is use multiple times and reuses common ones.

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

What is the String pool?

A

The place containing literal values that appear in your program. For example: “hello” would be in the string pool whereas myObject.toString() would not be in the String pool.

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

Would “hello” be in the string pool

A

yes

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

would myOjbect.toString() be in the string pool?

A

no

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

How does the string pool handle this? String name = “fluffy”; String name = new String(“fluffy”);

A

The first is stored in the string pool. The second says, “No, JVM. I really don’t want you to use the string pool for this one. Make a new object for me even though it is less efficient.

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

Why does the string pool exist?

A

Because strings take up a lot of memory. So the pool stores literals and watches for ways to reuse preexisting literals where possible.

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

With Strings, where does Java index from?

A

0 (only when indexing

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

What does myString.length() return?

A

an int count of the length of myString

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

What’s the method signature for length()

A

int length()

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

What’s the method signature for charAt()

A

char charAt(int index)

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

What does charAt(int index) return?

A

The char at a specified index

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

What does this return? String string = “animals”; sysout(charAt(0)); sysout(charAt(6)); sysout(charAt(7));

A

a s throws out of bounds exception because charAt indexes from 0. So max range would be 0-6.

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

What does indexOf() do?

A

indexOf() looks at the characters in a string and finds the earliest occurrence, returning the index of the first occurrence as an int.

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

What do these return? String string = “animals”; sysout(string.indexOf(‘a’));

sysout(string.indexOf(“al”));

sysout(string.indexOf(‘a’,4));

sysout(string.indexOf(“al”,5));

A

0

4

4 (don’t even look for any matches until you get to the index of 4)

-1 (negative one means no matches were found) Remember that you need double quotes for more than one letter

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

Does indexOf throw an error if it doesn’t find a match?

A

No. It will return -1 if it doesn’t find anything.

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

What are the method signatures for indexOf()? (4)

A

int indexOf(int ch); int indexOf(char ch, int fromIndex); int indexOf(String str); int indexOf(String str, index fromIndex);

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

What are the method signatures for substring()?

A

String subString(int beginIndex); String subString(int beginIndex, int endIndex);

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

What does substring() do?

A

The method returns the string starting from the requested index. If an end index is requested, it stops right before that index. Otherwise, it goes to the end of the string.

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

What does this return? String string = “animals”; System.out.println(string.substring(3)); System.out.println(string.substring(string.indexOf(‘m’))); System.out.println(string.substring(3, 4)); System.out.println(string.substring(3, 6)); System.out.println(string.substring(3, 8)); System.out.println(string.substring(3,3)); System.out.println(string.substring(3,2));

A

mals mals m mal error empty string error Remember, the last index is not INCLUDING. It’s says, “include up to this index”. If an endIndex is requested it stops right there.

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

What do String toLowerCase() and String toUpperCase() do?

A

Keeping in mind that strings are immutable, toUpperCase and toLowerCase return strings that are either now upper or lower case. They only touch characters that are letters.

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

What does boolean equals(Object obj) do?

A

It compares whether two objects have the exact same bits. You can only call this on objects. Not primitives.

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

What does boolean equalsIgnoreCase(Object obj) do?

A

Checks whether two String objects contains exactly the same letters in the same order with the exception that it will convert case when it needs to)

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

What’s the output? String string = “animals”; String string2 = new String(“animals”); String string3 = “animals”; System.out.println(string.equals(“animals”)); System.out.println(string.equals(string2)); System.out.println(string.equalsIgnoreCase(new String(“animals”))); System.out.println(string==string2); System.out.println(string==”animals”); System.out.println(string==new String(“animals”)); System.out.println(string==string3);

A

true true true false true false true remember it is case sensitive unless told to not be so

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

What do these methods do? boolean startsWith(String prefix) boolean endsWith(String suffix)

A

They look at whether or not the string ends with or starts with the provided values

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

What’s the output? String name = “jedd”; System.out.println(name.endsWith(“dd”)); System.out.println(name.endsWith(“DD”));

A

true false remember it is case sensitive

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

What does boolean contains (String str) do?

A

It looks for matches with in the string regardless of whether it starts with/ends with or whatever. it doesn’t care. also case sensitive

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

What is the output? String name = “jedd”; System.out.println(name.contains(“dd”)); System.out.println(name.contains(“DD”));

A

true false

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

What does the replace method do? String replace(char oldChar, char newChar) String replace(CharSequence oldChar, CharSequence newChar)

A

The replace method does a simple search and replace on the string.

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

What is the output: System.out.println(“abcabcabc”.replace(‘c’, ‘b’)); System.out.println(“abcabcabc”.replace(“a”, “A”));

A

abbabbabb AbcAbcAbc Note: the second method is not the same as the first. This is looking for a CharSequence or a String and replacing it with another String.

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

What does the trim() method do? public String trim()

A

The trim() method removes whitespace from the beginning and the end of a string. So on the exam this means \t (tab and \n newline characters get trimmed.

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

What is the output? public static void main(String[] args) { System.out.println(“abc”.trim()); System.out.println(“\t a b c\n”.trim()

A

abc a b c The second drops the leading tab, subsequent spaces, and the trailing newline. Note that it leaves the spaces in the middle of the spring.

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

What happens when you call a String method on a String? What happens if you call many methods on a String?

A

You make a new String each time. Each time one is called, the returned value is put in a new variable.

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

What does the Stringbuilder class do?

A

Creates a String without storing all the interim values that occur as you iterate through string objects. String immutability means that each time you “change” a String you are actually making a new one. Often making the old one eligible for garbage collection almost immediately. String builders change their own state and then return references to themselves.

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

Are instances of StringBuilder s immutable?

A

no

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

What is the output and why? StringBuilder a = new StringBuilder(“abc”); StringBuilder b = a.append(“de”); b = b.append(“f”).append(“g”); System.out.println(a); System.out.println(b); System.out.println(a==b);

A

abcdefg abcdefg true There is only one StringBuilder object here. We know that because new StringBuilder9) was called only once.

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

How many string objects does this piece of code create? String alpha = “”; for(char current = ‘a’; current <= ‘z’; current++){ alpha+=current; System.out.println(alpha);

A
  1. A new string is made with the addition of each new character. (initial empty string + addition of each character of the alphabet). Note that as each string is created the string that it replaced is now available for garbage collection.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

How many string objects does this code generate? StringBuilder alpha = new StringBuilder(); for (char current = ‘a’; current <= ‘z’; current++) { alpha.append(current); System.out.println(alpha); }

A

Just one. This code reuses the same String building without creating an interim string each time.

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

How does String handle method chaining?

A

It creates a new string each time.

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

How does StringBuilder handle method chaining?

A

StringBuilders change their own state and returns a reference to itself.

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

What is the output? StringBuilder sb = new StringBuilder(); sb.append(“+middle”); StringBuilder same = sb.append(“+end”); System.out.println(sb); System.out.println(sb == same);

A

+middle+end true

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

What’s the difference between StringBuilder() and StringBuffer()?

A

String Buffer is an older thread safe version of string builder.

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

What is the output? StringBuilder() one = new StringBuilder(); StringBuilder() two = new StringBuilder(); StringBuilder() three = one.append(“a”); Sysout(one == two); Sysout(one == three);

A

False True Remember string builders return references to themselves.

54
Q

What is the output? String x = “Hello world!”; String y = “Hello world!”; sysout(x == y);

A

This is true because of how the JVM deals with string literals. Strings are immutable and literals are pooled.

55
Q

What is the output? String x = “Hello world!”; String y = “Hello world!”.trim(); sysout(x == y);

A

True.

56
Q

What is the output? String x = “Hello world!”; String y = new String(“Hello world!”); sysout(x == y);

A

false. As you have specifically requested a new string object the pooled value literal won’t be shared

57
Q

What is the output? Tiger t1 = new Tiger(); Tiger t2 = new Tiger(); Tiger t3 = t1; Sysout(t1==t3); sysout(t1==t2); sysout(t1.equals(t2));

A

true false false

58
Q

What do String and StringBuilder composed of?

A

They are both arrays of characters?

59
Q

What is an array?

A

An array is an area of memory on the heap with space for a designated number of elements.

60
Q

Can arrays be of any Java type?

A

yes

61
Q

char[] letters; Is letters a primitive or a reference variable?

A

Reference variable. char is a primitive but an array of chars is not.

62
Q

Describe this in a sentence: int[] numbers1 = new int[3];

A

This is an array of ints that can contain three elements.

63
Q

When you first make an array, what are the default values?

A

Whatever the default value is for the type of array we are dealing with.

64
Q

Do all of these compile? int[] numbers; int [] numbers; int numbers[]; int numbers [];

A

yes

65
Q

Do both of these compile? int [] numbers = new int[] {43,43,43}; int[] numbers = {43,43,43};

A

Yes. Java recognizes the “new int[]” as redundant. The second wouldn’t be considered an anonymous array, anonymous because we haven’t specified the size and the type.

66
Q

What does this create? int [] ids, types; int ids[], types;

A

The first makes two variables of the type int[]. The second makes one int array and one int.

67
Q

How does the .equals() method work on arrays?

A

Checks to see if the references are the same.

68
Q

How does this array work? String [] stuff = {“do”, “try”, “go”};

A

Stuff stores references to those string objects.

69
Q

What does this array point to? String names[];

A

null

70
Q

What does this array do? String names[] = new String[2];

A

This is an array with a capacity of two. Currently, both of the values are null. But each null has the capacity to point to a string object.

71
Q

Do each of these compile?

String[] strings = {“stringValue”};

Object[] objects = strings;

String [] moreStrings = (String[]) objects;

moreStrings[0] = new StringBuilder();

objects[0] = new StringBuilder();

A

String[] strings = {“stringValue”}; yes

Object[] objects = strings; yes, doesn’t require cast because Object is more broad than String.

String [] moreStrings = (String[]) objects; yes Cast needed because we are moving to a more specific type

moreStrings[0] = new StringBuilder(); no, bad type so no compile

objects[0] = new StringBuilder(); no Object can store StringBuilders, but we don’t have an Object array at this point. objects is pointing to a string array.

72
Q

Why doesn’t this compile? int [] numbers = new int[10]; for (int j = 0 ; j<= numbers.length; j++){ numbers[j] = j+5; System.out.println(numbers[j]); }

A

<= causes array index out of bounds.

73
Q

What is the output? int [] numbers = {6,9,1}; Arrays.sort(numbers); for (int j = 0; j < numbers.length; j++){ System.out.print(numbers[j] + “ “) }

A

1 6 9;

74
Q

Can you do an index search on advanced for loops?

A

no. Only with iterators.

75
Q

You can search an array, but what must be done first?

A

It must be sorted.

76
Q

What are the three binary search rules?

A

Target element found in sorted array (Result) Index Target element not found in sorted array (Result) Negative value showing one smaller than the negative index, where a match needs to be inserted to preserve sorted order. Unsorted array (Result) A surprise–this result isn’t predictable

77
Q

What is the output? int [] numbers = {2,4,6,8}; System.out.println(Arrays.binarySearch(numbers,2)); System.out.println(Arrays.binarySearch(numbers,4)); System.out.println(Arrays.binarySearch(numbers,1)); System.out.println(Arrays.binarySearch(numbers,3)); System.out.println(Arrays.binarySearch(numbers,9));

A

0 1 -1 -2 (3 would be at the index of 1, negate, minus 1 to get -2) -5 (9 this would be at index of four, we negate, minus 1 to get this result) The binary search tells us at which index the number is found OR at which index it would be found if it were part of a sorted list.

78
Q

Can you use varargs as an array?

A

yes. (Think main(String..args))

79
Q

What do each of these represent? int[][] vars1; int vars [][]; int[] vars3[]; int[] vars4 [], space[][][]

A

one 2d array one 2d array one 2d array one 2d array and one 3d array

80
Q

Say this in readable language: String [] [] rectangle = new String[3][2];

A

rectangle is a reference to 3 elements which happen to be 2 dimensional arrays.

81
Q

Say this in readable language: int [] [] differentSize = {{1,4},{3},{9,8,7}};

A

differentSize is a two dimensional int array. The first element is a 2d array with the values of 1 and 4 at index 0 and 1. The second array has one element (3) at the index of 0. The third element/array is an array with the values 9, 8, and 7 at index 0,1,2.

82
Q

Say this in readable language: int [] [] args = new int[4][]; args[0] = new int[5]; args[1] = new int[3];

A

The first line initialize a 2d array. It also says the first dimension of the array has four elements, or four places that can contain an array. Lines 3 and 4 give the first and second element array sizes, respectively, 5 and 3.

83
Q

What is the output? int[][] twoD = new int[3][2]; for (int j = 0; j< twoD.length; j++) { for (int k = 0; k < twoD[j].length; k++) { System.out.print(twoD[j][k] + “ “ ); System.out.println(); } }

A

0 0 0 0 0 0 This finds the first array (of three available) and prints out each value. Then it goes to the next array in order. So from index of 0 to index of 1 and so on.

84
Q

What’s a glaring short coming of an array?

A

You have to know how many elements will be in the array when you create it and you are stuck with that choice under threat of index out of bounds errors.

85
Q

StringBuilder is to String as ____ is to an array?

A

ArrayList

86
Q

What is an ArrayList?

A

an ordered sequence that allows duplicates–like an array–but that can grow from the initial size you set, unlike an array.

87
Q

Does this compile? ArrayList list1 = new ArrayList(); ArrayList list2 = new ArrayList(10); ArrayList list3 = new ArrayList(list2); ArrayList list4 = new ArrayList(); ArrayList list5 = new ArrayList<>();

A

yes. note that the last two are better because of generics.

88
Q

What is the diamond operator?

A

<>

89
Q

Which interface does ArrayList implement?

A

List. In other words, ArrayList is a list.

90
Q

Why can’t you store an ArrayList in a List reference variable?

A

Because List is an interfaces so it can’t be instantiated.

91
Q

Does this compile? List list6 = new ArrayList<>(); ArrayList list7 = new List<>();

A

The first, yes. The second, no. List is an interface so it’s can’t be instantiated.

92
Q

What does E mean in the context of generic arrays?

A

E is used by convention in generics to mean “any class that this array can hold.”

93
Q

What’s the default type for an ArrayList if you don’t specify a type?

A

object

94
Q

Method signatures for ArrayList.add() = boolean add(E element) void add(int index, E element)

A

Add an element to the end or add an element to an index.

95
Q

What is the output? ArrayList list = new ArrayList(); list.add(“hawk”); list.add(true); list.forEach(System.out::println);

A

hawk, true This works as we didn’t specify a type so any Object (so non primitive) works.

96
Q

What is the output? ArrayList list = new ArrayList<>(); list.add(“sparrow”); list.add(“Boolean.TRUE);

A

The first add work but the second doesn’t because we have used generics to specify a type.

97
Q

Method signatures for ArrayList.remove() = boolean remove(Object object) E remove( int index)

A

Boolean tells us whether the object was removed. The E return type is the element that actually got removed

98
Q

What is the output? List birds = new ArrayList<>(); birds.add(“hawk”); birds.add(“hawk”); System.out.println(birds.remove(“cardinal”)); System.out.println(birds.remove(“hawk”)); System.out.println(birds.remove(0));

A

false true hawk note only one hawk string was removed.

99
Q

What does this do? E set(int index, E newElement) Note that the E return type is the element that was replaced

A

The set Method changes one of the elements of the ArrayList without changing the size.

100
Q

What is the output? List birds = new ArrayList<>(); birds.add(“hawk”); System.out.println(birds.size()); birds.set(0, “robin”); System.out.println(birds.size()); birds.set(1, “robin”);

A

Index out of bounds as the array only has a size of one. The set method only replaces the element, it does not add another.

101
Q

What does this method do? boolean ArrayList.isEmpty()

A

If there are no elements it returns true.

102
Q

What does this method do? ArrayList.size() int size()

A

Returns the number of elements in the ArrayList.

103
Q

What is the output? List birds = new ArrayList<>(); System.out.println(birds.isEmpty()); birds.add(“hawk”); System.out.println(birds.isEmpty()); System.out.println(birds.size());

A

true false 1

104
Q

What does this method do? ArrayList.clear() void clear()

A

Discards all the elements in an ArrayList.

105
Q

What is the output: List birds = new ArrayList<>(); System.out.println(birds.isEmpty()); birds.add(“hawk”); System.out.println(birds.isEmpty()); birds.add(“doggle”); System.out.println(birds.size()); birds.clear(); System.out.println(birds.size());

A

true false 2 0

106
Q

What does this method do? ArrayList.contains() boolean contains(Object object)

A

contains() check whether a certain value is in the array list. It does so by calling equals() on each element of the ArrayList to see if there are any matches.

107
Q

What is the output: List birds = new ArrayList<>(); birds.add(“hawk”); birds.add(“doggle”); System.out.println(birds.contains(“hawk”)); System.out.println(birds.contains(“Hawk”));

A

true false

108
Q

What does this method do? ArrayList.equals() boolean equals(Object object)

A

This is a custom implementation of equals() so you can compare two lists to see if they contain the same elements in the same order.

109
Q

What is the output? List listOne = new ArrayList<>(); List listTwo = new ArrayList<>(); System.out.println(listOne.equals(listTwo)); listOne.add(“hawk”); System.out.println(listOne.equals(listTwo)); listTwo.add(“hawk”); System.out.println(listOne.equals(listTwo)); listOne.add(0,”doggle”); listTwo.add(“doggle”); System.out.println(listOne.equals(listTwo));

A

true false true false Remember, the order has to match.

110
Q

How is it possible to put primitives into an arrayList?

A

It’s not, we have to use the wrapper class provided for each primitive.

111
Q

Do wrapper classes have methods to convert themselves back to primitives?

A

Yes

112
Q

What does each line do? int primitive = Integer.parseInt(“123”); Integer wrapper = Integer.valueOf(“123”); int number1 = Integer.parseInt(“1.2”); Integer number2 = Integer.valueOf(“1.2”);

A

The first line is converting a string to a primitive (int in this case). The second line converts a string into the wrapper class Integer. The third and fourth lines throw errors because these methods won’t handle the decimal. If you wanted to do that you would need to use the Double wrapper valueOf method or the Double wrapper parseDouble method.

113
Q

How would you convert a String to a primitive?

A

E.parseE(“ “);

Except Character, this does not of a way to convert the String to it’s primitive.

And remember the way to convert the string back to the primitive is to use the wrapper class and value of.

114
Q

How would you convert a String to a wrapper class?

A

E.valueOf(“ “);

115
Q

Which primitive doesn’t have methods to convert a String to a primitive/wrapper class?

A

Character. Just use the String methods.

116
Q

What is auto boxing?

A

It’s when java converts a primitive to the relevant wrapper class.

117
Q

What is the output: List numbers = new ArrayList<>(); numbers.add(null); int h = numbers.get(0);

A

null pointer exception. It’s possible to add a null value, as a null value can be assigned to any reference variable, but not possible to assign a null value to a primitive.

118
Q

What do you get when you call a method on a null value?

A

You always get a null pointer exception.

119
Q
A
120
Q

What is a backed List?

A

A fixed sized list as the array changes with the list. You are not allowed to change the size of a list. When a change is made in one, the value is available in the other

121
Q

What is the output and how do we know this is a backed list? Will this compile? String[] array = {“hawk”, “robin”}; List list = Arrays.asList(array); System.out.println(list.size()); list.set(1, “test”); array[0] = “new”; for (String b : array) System.out.println(b); list.remove(1);

A

Note that we made changes to the list but the values were made available to the array. Note that removing it throws an unsupported operation exception. were it not for that, the out put would be new test.

122
Q

What is the output? String[] array = {“hawk”, “robin”}; List list = Arrays.asList(array); System.out.println(list.size()); list.set(1, “test”); list.add(“hey”); array[0] = “new”; for (String b : array) System.out.println(b);

A

Unsupported operation exception. You cannot change the size of an array

123
Q

What is the output? String[] array = {“hawk”, “robin”}; List list = Arrays.asList(array); System.out.println(list.size()); list.set(1, “test”); list.add(“hey”); array[0] = “new”; for (String b : array) System.out.println(b);

A

Unsupported operation exception. You cannot change the size of an array

124
Q

What is the output? List numbers = new ArrayList<>(); numbers.add(99); numbers.add(5); numbers.add(10); Collections.sort(numbers); System.out.println(numbers);

A

[5, 10, 99]

125
Q

What’s the import for dealing with dates and times?

A

import java.time.*;

126
Q

What does will each of these classes expose for use? LocalDate LocalTime LocalDateTime

A

LocalDate - just a date, no time and no time zone. like 01-01-01 LocalTime - Just the time, no date and no time zone LocalDateTIme - Date and time but no time zone

127
Q

What would the out put of each be whenever this is read? System.out.println(LocalDate.now()); System.out.println(LocalTime.now()); System.out.println(LocalDateTime.now()); System.out.println(LocalDate date = new LocalDate()):

A

Something like: 2018-10-15 19:34:49.031 2018-10-15T19:34:49.031 Does not compile. Date methods are static and only static.

128
Q

What is the output: System.out.println(LocalTime.of(9,30)); System.out.println(LocalTime.of(9,30, 30)); System.out.println(LocalTime.of(9,30, 30, 30));

A

09:30 09:30:30 09:30:30.000000030

129
Q

What is the output: LocalDate date1 = LocalDate.of(2018, Month.OCTOBER, 13); LocalTime time1 = LocalTime.of(9, 30); System.out.println(LocalDateTime.of(2015,Month.JANUARY,9,9,30)); System.out.println(LocalDateTime.of(date1, time1)); System.out.print(LocalDateTime.of(2018,11,2,9,30));

A

2015-01-09T09:30 2018-10-13T09:30 2018-11-02T09:30

130
Q

Are date and time classes mutable or immutable?

A

Immutable