Add to stack from ArrayList (Java)

arraylist, java, stack

Solution

Like many collection classes, Stack provides a addAll method :

st.addAll(al)

Problem

I have an ArrayList pre-defined with hardcoded values. How do I add these to a stack? The idea is to demonstrate the pop, push, peek functions of the stack class. ``` ArrayList<String> al = new ArrayList<String>(); al.add("A"); al.add("B"); al.add("C"); Stack<String> st = new Stack<String>(); st.push(al); **// This doesn't seem to work.. Will I have to loop it in some way?** System.out.println(st); ``` Thanks!

Original source