Unit 7 ArrayList HW - Meena Annamalai
HW for Unit 7
- Sort an ArrayList in descending order and swap the first and last elements and
- Find and display the hashCode of an Arraylist before and after being sorted
- Do two hacks of the 4
- Sort an ArrayList in descending order and swap the first and last elements (Completed)
- Find and display the hashCode of an Arraylist before and after being sorted (Completed)
- Return "ascending" if the list is sorted in ascending order, return "descending" if it is descending, and return "neither" if neither
- Replace 3 elements in an ArrayList with another ArrayList and reverse the order of the new list
ArrayList<Integer> numbers = new ArrayList<Integer>();
numbers.add(1);
numbers.add(4);
numbers.add(2);
numbers.add(3);
System.out.println("Before Sorting: "+ numbers + ", the hashcode is " + numbers.hashCode());
Collections.sort(numbers, Collections.reverseOrder());
System.out.println("After Sorting: "+ numbers + ", the hashcode is " + numbers.hashCode());
Collections.swap(numbers, 0, numbers.size()-1);
System.out.println("After Sorting and Swapping first and last numbers: "+ numbers + ", the hashcode is " + numbers.hashCode());