How do I append an element to the end of an ArrayList in Java? Here is my code:
public class Stack {
private ArrayList<String> stringList = new ArrayList<String>();
RandomStringGenerator rsg = new RandomStringGenerator();
private void push(){
String random = rsg.randomStringGenerator();
ArrayList.add(random);
}
}
“randomStringGenerator” is a method that generates a random string at the end of the ArrayList, much like a stack.