[JAVA] standard iterative solution
\nclass Solution {\n    public List<Integer> preorderTraversal(TreeNode root) {\n     ArrayList<Integer> ans = new ArrayList<Integer>();\n      if(root == null)
```\nclass Solution {\n    public List<Integer> preorderTraversal(TreeNode root) {\n     ArrayList<Integer> ans = new ArrayList<Integer>();\n      if(root == null) return ans;\n      \n      Stack<TreeNode> st = new Stack<TreeNode>();\n      st.push(root);\n      \n      while(!st.isEmpty()) {\n        TreeNode cur = st.pop(); \n        ans.add(cur.val);\n        \n          if(cur.right != null) st.push(cur.right);\n          if(cur.left != null) st.push(cur.left);\n      }\n      return ans;\n    }\n}\n```\n# KINDLY UPVOTE IF IT WAS HELPFULL
['Stack', 'Binary Tree', 'Iterator', 'Java']