I am working on a User login service. Below I am pulling data from a text file to create an array of user objects. I then need to compare console input to see if it matches any of the objects in the the Array, specifically username (array position [0]) and password (array position [1]). I am assigning input to String username and String password. How can I then see if those inputs are at array [0] or [1] in any of the user objects.
public static User[] createArray() throws IOException {
User[] users = new User[4];
BufferedReader fileReader = null;
try {
fileReader = new BufferedReader(new FileReader("data.txt"));
String line;
int i = 0;
while ((line = fileReader.readLine()) != null) {
users[i] = new User(line.split(","));
System.out.println(line);
System.out.println(users[i]);
i++;
}
} finally {
if (fileReader != null)
fileReader.close();
}
return users;