5. Working with Strings, Arrays and ArrayLists Flashcards
True or False: All string methods use zero-based indexes ?
There is only one exception - the second argument of
substring() is not zero-based.
When we are talking about Strings and Arrays - length() or length ?
Strings have a method called length()—arrays have an attribute named length.
What is the difference when you create an array of objects and an array of primitives.
Elements in an array of objects are not automatically created, although primitive array elements are given default values.
Can a byte variable go in an int array ?
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.
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};
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[]{};