How to append elements at the end of ArrayList in Java? -
i wondering, how append element end of arraylist in java? here code have far:
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" method generates random string.
i want append random string @ end of arraylist, stack (hence name "push").
thank time!
here syntax, along other methods might find useful:
//add end of list stringlist.add(random); //add beginning of list stringlist.add(0, random); //replace element @ index 4 random stringlist.set(4, random); //remove element @ index 5 stringlist.remove(5); //remove elements list stringlist.clear();
Comments
Post a Comment