5. Working with Strings, Arrays and ArrayLists Flashcards

1
Q

True or False: All string methods use zero-based indexes ?

A

There is only one exception - the second argument of
substring() is not zero-based.

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

When we are talking about Strings and Arrays - length() or length ?

A

Strings have a method called length()—arrays have an attribute named length.

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

What is the difference when you create an array of objects and an array of primitives.

A

Elements in an array of objects are not automatically created, although primitive array elements are given default values.

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

Can a byte variable go in an int array ?

A

An array of primitives can accept any value that can be promoted implicitly to the array’s declared type, so the answer is yes - a byte variable can go in an int array.

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

Which of the following will compile successfully:

int eArr1[] = {10, 23, 10, 2};
int[] eArr2 = new int[10];
int[] eArr3 = new int[] {};
int[] eArr4 = new int[10] {};
int eArr5[] = new int[2] {10, 20};

A

Defining the size of the array while using {} is not correct. Both of the following lines of code are correct:

int[] eArr4 = new int[10];
int[] eArr4 = new int[]{};

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