Hey, I'm doing a store for student parts, and I need some opinions on which collection to use. The store will include information such as name, number, address and email address. Then the repository will be printed in a text file, where I can load, save, edit and delete parts in a text file. I have never done this before, and I don't know if there are any restrictions on file input / output when using collections. Therefore, I will be very grateful for the comments. Thanks in advance.
If I were with you,
bean Student ArrayList<Student> student = new ArrayList<Student>(); ArrayList class IO .
Student
ArrayList<Student> student = new ArrayList<Student>();
ArrayList
class
IO
, , .
List<Student> students = new ArrayList<Student>();
, , , LinkedHashMap:
LinkedHashMap
Map<String,Student> studentById = new LinkedHashMap<String,Student>();
LinkedHashMap . HashMap<K,V>, . , TreeMap<K,V>, .
HashMap<K,V>
TreeMap<K,V>
, , , List. , - , List, , List. , List , . List<Student> .
List
List<Student>
EDIT
, - . - , is-a , . , Java API List, , ArrayList, . ArrayList List. ArrayList Serializable, , , ( Java). casting Serialize List. , , , ( ), , .
is-a
Serializable
Serialize
In the simplest case, a java.util.Listwill do exactly what you want. However, if you want to quickly find entries in the collection (to support your upgrade requirements), you can also look java.util.Map. The card allows you to quickly navigate through a particular record without having to repeat it throughout the collection, while with the list you should look at each student in the collection one by one until you find the one you are interested in.
java.util.List
java.util.Map