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
Naresh Kumar Mohan ThirukkovaluruNaresh Kumar Mohan Thirukkovaluru 

how to pass data from list to set collection?

Denis VakulishinDenis Vakulishin
Could you give more details or/and code samples of what exactly you're trying to do ?
anil savaliya 11anil savaliya 11
Hey Naresh,

Make for loop for list and add value in set collection.
Denis VakulishinDenis Vakulishin
Actualy just copying values from list to set isn't correct solution.
From Docs about Set
"Represents a collection of unique elements with no duplicate values."
List can contains duplicate values, Set  not. 
So in FOR loop case you should also do check for set.contains(), so only if it false you can add value to the Set collection
Shri RajShri Raj
List<Account> accList = new List<Account>
Set<Account> accSET = new Set<Account>
For(Account acc : accLIst) {
  accSet.add(acc) ;