packageidv.carl.datastructures.stack;/** * @author Carl Lu */publicclassReverseString {publicStringdoRevert(String input) {StringBuffer result =newStringBuffer();Stack stack =newStack(100);// Step1. Read the string as chars one by onechar[] chars =input.toCharArray();// Step2. Push those chars into the stack sequentiallyfor (char c : chars) {stack.push(c); }// Step3. Pop all chars to form a new stringwhile (!stack.isEmpty()) {result.append((char) stack.pop()); }returnresult.toString(); }}