Here you can find the source of listToStack(List
public static <T> Stack<T> listToStack(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Stack; public class Main { public static <T> Stack<T> listToStack(List<T> list) { Stack<T> stack = new Stack<>(); for (int i = list.size() - 1; i >= 0; i--) stack.push(list.get(i));//from w w w.jav a 2s.com return stack; } }