Chapter 6 - Single-Dimensional Arrays Flashcards
For finding the length of an array, should you use arrayVar.length() or arrayVar.length? What about strings? stringVar.length() or stringVar.length?
.length for arrays, .length() for strings
What method can you use to sort arrays?
java.util.Arrays.sort(myArray). This method doesn’t return anything, it just sorts the given array.
What method can you use to search for a key in an array?
you can use java.util.Arrays.binarySearch(myArray, key). The array must be pre-sorted in ascending order before using binarySearch. If key is present, the method returns the index of the key. If not present, method returns -(insertionindex + 1)
How can you compare two arrays to check if they’re the same?
Use the method java.util.Arrays.equals(list1, list2). If the lists have the same content and in the same order, the method returns true. If same content, but not same order, returns false.
What does the method java.util.Arrays.fill do?
java. util.Arrays.fill(list1, x) fills the whole array with whatever value is in x, and overrides whatever was there before. Optionally you can fill only a part of the array:
java. util.Arrays.fill(list1, startIndex, endIndex, x)
What does the java.util.Arrays.toString(myArray) method do?
It returns the content of the list as one whole string, including square brackets at start and end.
binary search, linear search, selection sort, insertion sort
study these….
What’s the difference between changing arrays and non-array-arguments inside methods?
Changing a passed-in argument inside a method does not change the object outside the method, but changing a passed-in array will also change the array outside the method
Which of the following is incorrect?
A. int[] a = new int[2]; B. int a[] = new int[2]; C. int[] a = new int(2); D. int a = new int[2]; E. int a() = new int[2];
C, D and E are incorrect
What is the correct term for numbers[99]?
A. index B. index variable C. indexed variable D. array variable E. array
C. indexed variable