1

I want to declare an ArrayList within another ArrayList.

I declared ArrayList of ArrayList and added the elements in the following manner successfully but at the time of retrieval its showing class cast exception.

List<List<UnderDefinedFunction> parentAL=new ArrayList<List<UserDefinedFunction>>();
List<UserdefinedFunction> childAL=new ArrayList<UserDefined>();

childAL.add(userdefinedfunction);
...............
..............
parentAL.add(childAL);

At the time of retrieval it is showing class cast exception.

for(int i=0;i<parentAL.size();i++){
    List<UserDefinedFunction> al=parentAL.get(i);
}

I tried with following code also:

ArrayList<ArrayList<UserDefinedfunction> al=new ArrayList<ArrayList<UserDefinedFunction>>();

but I am getting same problem.

Why is it showing any error any mistake is done any idea ???

0

1 Answer 1

4

Do:

 List<ArrayList<UnderDefinedFunction>> parentAL=new ArrayList<ArrayList<UserDefinedFunction>>();

instead and it will work.

Sign up to request clarification or add additional context in comments.

2 Comments

i am getting same error can you please provide the code for retrieval @Kai
i tested that code you pasted here. for me it works fine. the problem is at another point in your code. pls post the stacktrace and maybee more code. and the way you retrieval the list is correct too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.