The best collection for storing student information?

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.

+5
source share
4 answers

If I were with you,

bean Student ArrayList<Student> student = new ArrayList<Student>(); ArrayList class IO .

ArrayList

+4

, , .

List<Student> students = new ArrayList<Student>();

, , , LinkedHashMap:

Map<String,Student> studentById = new LinkedHashMap<String,Student>();

LinkedHashMap . HashMap<K,V>, . , TreeMap<K,V>, .

+3

, , , List. , - , List, , List. , List , . List<Student> .

EDIT

, - . - , is-a , . , Java API List, , ArrayList, . ArrayList List. ArrayList Serializable, , , ( Java). casting Serialize List. , , , ( ), , .

+1

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.

0
source

All Articles