如何创建一个可以存储多个对象的arraylist类?

我是一个自学者。 目前,我正在制作一个GUI项目,我需要一个matrice类型的数据库。

我想学习如何创建一个可以在arraylist中存储多个对象的类。

这是我的示例代码。 请注意,这只是我的尝试。 此代码尚未最终确定,并且无效。

谢谢你的热心帮助。

import java.util.ArrayList; import java.util.List; 

}}

我认为更好的方法是创建一个用户信息类来存储像这样的特定用户的信息。

 // I made them all public but this might not be a good idea! class UserInfo { String user; String pass; String secretCode; } 

然后你把它放到一个ArrayList中。

 ArrayList  InfoList = new ArrayList (); 

然后,对于您当前的方法,您可以这样做

 // Not so sure what you want to do in this method... so you get to figure out that yourself! public void userInternalDatabase (UserInfo info) { this.user = info.user; this.pass = info.pass; this.secretCode = info.secretCode; } public void addUser(String i, String j, String k) { UserInfo newUser = new UserInfo(); newUser.user = i; newUser.pass = j; newUser.secretCode = k; InfoList.add(newUser); } public Object findUsername(String a) { for (int i=0; i