Question: Assuming we have an ArrayList ArrayList aList = new ArrayList (); aList.add(10.0); //this works aList.add(10); //this will not work Explain why the add() function


 


Assuming we have an ArrayList ArrayList aList = new ArrayList (); aList.add(10.0);

Assuming we have an ArrayList ArrayList aList = new ArrayList (); aList.add(10.0); //this works aList.add(10); //this will not work Explain why the add() function works in the first case but fails in the second case. Is there any problem with casting?

Step by Step Solution

3.50 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

In Java ArrayList is a generic class meaning it can store objects of a specified ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!