function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lalit kumar 26Lalit kumar 26 

hi, there is an integer list of (1,2,3,4,4). I want to copy this list in another list in such a way that list should not copy the number 4 twice. It should copy in a list not in set.

hi,
there is an integer list of (1,2,3,4,4). I want to copy this list in another list in such a way that list should not copy the number 4 twice. It should copy in a list not in set. What would be the code ?

thanks
lalit
Best Answer chosen by Lalit kumar 26
ManojjenaManojjena
Hi Lalit,

Set is required to remove duplicate .You can try like below which will help you to solve your problem .
 
List<Integer> numList=new List<Integer>{1,2,3,4,4};
List<Integer> intLst=new List<Integer>(new Set<Integer>(numList));
System.debug('**********'+intLst);

Let me know if it helps !!
Thanks 
Manoj

All Answers

ManojjenaManojjena
Hi Lalit,

Set is required to remove duplicate .You can try like below which will help you to solve your problem .
 
List<Integer> numList=new List<Integer>{1,2,3,4,4};
List<Integer> intLst=new List<Integer>(new Set<Integer>(numList));
System.debug('**********'+intLst);

Let me know if it helps !!
Thanks 
Manoj
This was selected as the best answer
Lalit kumar 26Lalit kumar 26
hi manoj. 
 I got the output. But can we do it using for loop ? This is the requirement.
thanks