A simple Java program demonstrating the power of the Collections class with an ArrayList<Double> including sorting, binary searching, and filling lists with new values.
- Create and print an
ArrayList<Double> - Sort the list using
Collections.sort() - Search for a specific value with
Collections.binarySearch() - Replace all list elements using
Collections.fill()
Make sure Java 21 (or newer) is installed.
Then compile and run the program:
javac src\cop2805\CollectionsDouble.java
java -cp src cop2805.CollectionsDoubleOriginal List: 1.5 2.35 -4.7 0.01
Sorted List: -4.7 0.01 1.5 2.35
Found 1.5 at index 2 Zero List: 0.0 0.0 0.0 0.0
