If I understood correctly, you already have an ArrayList<String>
that contains previously entered strings and when a new string is entered by the user it is appended to this list.
What you would like to do is to select a random string from this list.
You can use the java.util.Random
class to generate a random index from the list and return the word that is positioned on that index.
For example, the code bellow will print a random member of the test list on every execution.
Random random = new Random();
List<String> test = Arrays.asList("Text1","Text2","Text3","Text4");
System.out.println(test.get(Math.abs(random.nextInt()) % test.size()));
EDIT
As stated in the comments, replacing the Math.abs(random.nextInt()) % test.size()
with random.nextInt(test.size())
will make the code more readable and reduce the chances for generating a lot of duplicates (it will make the number distribution more uniform).