[SalesForce] Copy a list to another list

I have a custom object called skill_Review and I am creating a list in my controller using:

 List<Skill_Review__c> skillRev  = new List<Skill_Review__c>
    List<Skill_Review__c> results = [SELECT Id,Name,Skill__c,Level__c FROM Skill_Review__c where Interview__c =:review.id ];

I have another list named skillRev of type skill_review_c in my controller. I want to get each field value in result and put it in the skillRev. Basically I would like to clone results list to skillRev. How can I do this? Is there a way to access Skill__c from results in controller like results.Skill_c?

Best Answer

If you look into documentation

You can use list.clone()

Example

List<Skill_Review__c> results = [SELECT Id,Name,Skill__c,Level__c 
                                    FROM Skill_Review__c 
                                     where Interview__c =:review.id ];
    List<Skill_Review__c> skillRev = results .clone();

Like @Ashwani said you can use addAll() method here

  List<Skill_Review__c> skillRev =new List<Skill_Review__c>();
  skillRev.addAll(skillRev );
Related Topic