1) stop
2) don't think about how you'd do this in
java. think about how you'd do this with pencil, paper, and your own brain.
3) write down in English (or your natural language of choice) how you would do it.
4) Revise those steps until you could give them to a child, and they could follow them
5) Give that list to a child to find out where you went wrong explaining the steps, and revise. Repeat this as many times as necessary.
ONLY when you have done all the above should you consider writing a single line of code. If you are already thinking about array lists and strings, you haven't though through the problem yet. You are jumping the gun.