Introduction to ArrayList
Exercises on ArrayList
Consider the following text file that contains grades of the students in a certain course
12.5 19.75 11.25 10 15 13.25 14 9 10 19.75
Write a Java program, that
- read these grades from a file
- store every grade into an ArrayList called grades
after storing all elements into the ArrayList, write a method:
- max (ArrayList grades) that returns the maximum grade from the ArrayList
- min (ArrayList grades) that returns the minimum grade from the ArrayList
- average (ArrayList grades) that returns the average grade from the ArrayList
- remove_duplicate(ArrayList grades) that returns an ArrayList without any duplicate grade. All duplicated grades must be removed.
Test all these functions in a main method.
Solutions of Exercise 1
Create an ArrayList of String called strList that contains 10 string words. Create a method called search(String keyword, in minLength) that returns an ArrayList of String. The method should return all the words that contain the keyword and have a length no less than minLength. if minLength == -1, then it returns all words with any length