Preorder Traversal Java solution both iteration and recursion
// recursive\n    public class Solution {\n        public List<Integer> preorderTraversal(TreeNode root) {\n            List<Integer> result = new ArrayList<Int
    // recursive\n    public class Solution {\n        public List<Integer> preorderTraversal(TreeNode root) {\n            List<Integer> result = new ArrayList<Integer>();\n            if (root != null){\n                result.add(root.val);\n                result.addAll(preorderTraversal(root.left));\n                result.addAll(preorderTraversal(root.right));\n            }\n            return result;\n        }\n    }\n    \n    // iterative\n    public class Solution {\n        public List<Integer> preorderTraversal(TreeNode root) {\n            List<Integer> result = new ArrayList<Integer>();\n            if (root == null) return result;\n            Stack<TreeNode> stack = new Stack<TreeNode>();\n            stack.push(root);\n            while (!stack.isEmpty()){\n                TreeNode node = stack.pop();\n                result.add(node.val);\n                if (node.right != null) stack.push(node.right);\n                if (node.left != null) stack.push(node.left);\n            }\n            return result;\n        }\n    }
['Java']