简体   繁体   English

使用类存储大量信息

[英]Store Large Amount of Info Using Classes

I want to get various information from the user. 我想从用户那里获得各种信息。 Eg. 例如。 I want to get their forname,surname,address. 我想获取他们的姓氏,姓氏,地址。 I have a class to do so. 我有一堂课。 But I shall be reading in alot of information of many users. 但是我将阅读许多用户的大量信息。

For example. 例如。 User1 =; 用户1 =; User2 =; User2 =; all the way up to lets just say 200 different people. 一路说到200个不同的人。

My question is, if my class name is People. 我的问题是,如果我的班级名称是People。 Do I have to do this everytime?(I cant see this being the only way) 我是否必须每次都要这样做?(我看不到这是唯一的方法)

People user1 = new People(joe, bloggs, world);
People user2 = new People(mary, bloggs, universe); etc.

How would I go about doing this. 我将如何去做。 I was thinking of writing it out to a .txt file in that order but then I dont know how I would read it in/modify it if a user wanted to change his/her address. 我当时想按此顺序将其写到.txt文件中,但是我不知道如果用户想要更改其地址,我将如何读入/修改该文件。

EDIT: 编辑:

public static ArrayList<People> person= new ArrayList<People> ();

How do I add multiple new people to the array list and how do I know which position they are in? 如何将多个新人员添加到阵列列表中,以及如何知道他们所处的位置?

Can anyone help me with this or set me on the right track. 任何人都可以帮助我解决这个问题,或者让我走上正确的道路。 Like I said Ill have to be able store alot of info and access it to modify it Thanks. 就像我说的那样,病态必须能够存储大量信息并可以对其进行修改,谢谢。

您需要将该类的实例添加到ArrayList中:

people.add(new Person(...));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM