Results 1 to 5 of 5
- 01-15-2011, 04:36 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Adding items from one Array List to another Array List
I'm teaching myself java, and need to fill in an incomplete program.
In this case, I'm having trouble adding items from an ArrayList called Integer, to an ArrayList called Car. My problem is filling in line 23 from the Car class.
Here are the two classes:
The book is from the library, so the answer CD is long gone, and the publisher doesn't support it any more.
Any ideas?Last edited by Java-Guy; 01-19-2011 at 09:55 PM.
- 01-15-2011, 06:27 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
Have a look at this:
Do you think you can add an item from one list to the other list?Java Code:List<Apple> apples; List<Pear> pears;
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-15-2011, 06:38 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
So is there a way to convert it from on type to the other?
I guess I could use arr.get for each item in the array and put them into some variable, and then write those to the other array. Is there a better solution?
Thanks.
- 01-15-2011, 07:15 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
You can't put an apple in a list of pears (or vice versa), not even if you stick it in array first. There's something wrong with your design and you have to think again why you want to do this. Or you have to elaborate on your question because as I understand it now you want to use apples for pears.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-17-2011, 04:19 AM #5
Similar Threads
-
Adding \ removing items from Jlist
By Desperado in forum AWT / SwingReplies: 10Last Post: 12-17-2009, 12:48 PM -
Null Pointer Exception when adding items to ArrayList
By ShadowCopy in forum New To JavaReplies: 3Last Post: 08-27-2009, 09:23 AM -
Adding existing items to a project
By Katherine in forum EclipseReplies: 4Last Post: 01-20-2009, 04:23 AM -
Adding recieved items to Server repository.
By nel636 in forum New To JavaReplies: 1Last Post: 11-28-2008, 01:46 PM -
Adding items to a jComboBox
By tronovan in forum New To JavaReplies: 0Last Post: 08-08-2007, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks