我认为一种更好的方法是创建一个用户信息类来存储特定用户的信息。
// I made them all public but this might not be a good idea!class UserInfo { String user; String pass; String secretCode;}
然后将其放入ArrayList中。
ArrayList <UserInfo> InfoList = new ArrayList<UserInfo> ();
然后,对于您当前的方法,您可以
// 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 <InfoList.size(); i++) { if (InfoList.get(i).user.equals(a)){ return "This user already exists in our database."; } } return "User is not founded."; // no Customer found with this ID; maybe throw an exception}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)