Complete the code to sort the array using Arrays.sort.
int[] numbers = {5, 3, 8, 1};
java.util.Arrays.[1](numbers);The method Arrays.sort sorts the array in ascending order.
Complete the code to find the index of 7 in the sorted array using binary search.
int[] sorted = {1, 3, 5, 7, 9};
int index = java.util.Arrays.binarySearch(sorted, [1]);Binary search looks for the exact value. Here, we want to find 7.
Fix the error in the code to correctly sort the list of strings.
java.util.List<String> names = java.util.Arrays.asList("Bob", "Alice", "Eve"); java.util.Collections.[1](names);
The correct method to sort a list is Collections.sort.
Fill both blanks to create a map of word lengths for words longer than 3 characters.
java.util.List<String> words = java.util.Arrays.asList("cat", "house", "tree", "a"); java.util.Map<String, Integer> lengths = words.stream() .filter(word -> word.[1]() > 3) .collect(java.util.stream.Collectors.toMap(word -> word, word -> word.[2]()));
Strings use length() to get their length.
Fill all three blanks to create a sorted map of uppercase words longer than 2 characters.
java.util.List<String> words = java.util.Arrays.asList("dog", "cat", "elephant", "ox"); java.util.Map<String, String> result = words.stream() .filter(w -> w.[1]() > 2) .sorted() .collect(java.util.stream.Collectors.toMap( w -> w.[2](), w -> w.[3]() ));
Use length() to check word length, and toUpperCase() to convert words to uppercase.
