+ 2
If Iâm understanding your question correctly, yes, you could do something like this:
int n = //no. of usernames
String[][] userpass = new String[n][2];
for (int i=0; i<n; i++) {
userpass[i][0] = //enter username
userpass[i][1] = //enter password
}
This isnât an ideal solution, though, for two reasons:
1. Arrays have a fixed size. Never a good choice if you may want to change the number of entries later.
2. Each username/password pair is not inherently linked. They share the same row, which keeps it organized, but youâd have to jump through hoops to, say, retrieve the correct password given a particular username.
Instead, itâs more practical to use a class which uses key-value mappings, such as a HashMap: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
You could create a HashMap<String,String> and store each username/password pair with the method put(user, pass) and retrieve a password using get(user). Iâm sure youâll find use for some of the other methods in the documentation, as well.
Hope that helps!



