Collection
Collection refers to the action of grouping things to manage them together
- ArrayList
ArrayList
ArrayList is a library class in Java. We can access to a library class in Java via the following statement:
Once a class name has been imported from a package in the way above, we can use that class just as if it were one of our own classes. So we use ArrayList at the head of the MusicOrganizer class to define a files field:
The advantage of implementing ArrayList is that someone has invested time and effort to implement something useful, and we are getting access to this functionality almost for free by using this class.
Functionalities: add(int index), get(int index), size(), list(), remove(int index)
Generic classes
Generic classes are classes that require a second class type as a parameter which is used to declare the type of variable inside the class.
- ArrayList<String>
Diamond Notation
Effect of Removal
4.3 Add two file names - "0" "1" listFile(0) - "0" listFile(1) - "1" removeFile(0) list- File(0) The result is "1".
So when we remove one value in the array, the sequence inside the Array is rearranged, and the following value will automatically move one index forward.
4.4-4.6 4.8 4.9 4.10 4.14-4.15 4.16
Personal Reflection
I learned a new class called ArrayList, its functionalities, and advantages. Also, I got reviews of the content about OOP we learned in the last semester. I have almost forgotten everything I learn about programming at first. Although fortunately, those contents can be recalled easily, I should not stop programming otherwise I will forget the syntax again and waste time on recalling them.