Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two arrayLists diferent types.....
Java
ArrayList<Ergazomenos> erg = new ArrayList<Ergazomenos>();
ArrayList<Proistamenos> proist = new ArrayList<Proistamenos>();
copy(erg, proist);

I dont know how to copy ergazomenos to proistamenos. Can i use arraycopy?
Posted
Updated 12-Dec-10 9:36am
v2

1 solution

Hi Nikosv!

Java
import java.util.ArrayList;
import java.util.Collections;
Collections.copy(arrayList2,arrayList1);
//alternatively copyOfList = new ArrayList<Proista>((ArrayList<Proista>)listOfErgozToCopy);


This should work if Ergazos were derived from Proistas.


Cheers


Manfred
 
Share this answer
 
v2
Comments
nikosv 12-Dec-10 17:02pm    
hanks for the answear Manfred.
I want to copy all Ergazomenos to Proistamenos. Could you explain this?

copyOfList=new ArrayList((ArrayList)listOfErgozToCopy);


What is copyOfLIst and listOfErgozToCopy?
thanks anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900