ArrayList<LinkedList<TreeNode>> result = new ArrayList<LinkedList<TreeNode>>();
for(LinkedList<TreeNode> entry : result)
Why in for loop result is LinkedList<TreeNode> and not ArrayList<LinkedList<TreeNode>>?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You create
ArrayListofLinkedLists, so each element of yourArrayListis aLinkedList. This is what you wrote in your for loop: you are iterating over elements of ArrayList, i.e. overLinkedLists.And BTW, avoid writing concrete classes at the left side of assignment, i.e.
ArrayList<LinkedList<TreeNode>> result = new ArrayList<LinkedList<TreeNode>>();should be written as
List<List<TreeNode>> result = new ArrayList<List<TreeNode>>();now you can say:
for(List<TreeNode> entry : result)It is more flexible because you can change your implementation without changing any other code.