I have a jTextArea I want to use as an accounts panel by an administrator. The admin can append user + " " + password + " \n" to the jTextArea (one line per user + password). When someone tries to log in, the idea is to iterate through the lines in the admin's jTextArea and compare:

entered username / line 1 word 1, entered password / line 1 word 2,
entered username / line n word 1, entered password / line n word 2.

If a match is found, they are granted access.

I can put all the text in my jTextArea in one string, then use:

int	indexOf(" ") 
          Returns the index within this string of the first occurrence of the specified substring.

.. to get the index of the first space, which is right after the first word, compare the word before it, remove the found substring for the next step, etc.

Is my approach OK? can it be done better?

Why not just build the string userName + " " + password + "\n"
and use indexOf to see if that complete String is present in the textarea

Thank you JamesCherrill, works like a charm!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.