There is a methods which is accepting a parameter of type List<long?>
, I need to assign it to someTestModel ids, which are of type ISet<long>
.
public void testM1(List<long?> testIds)
{
var request = new someTestModel { ids= testIds };
}
We can convert the list into a set using the set() command, where we have to insert the list name between the parentheses that are needed to be converted. Hence, in the above case, we have to type the set(the_names) in order to convert the names, present in the list into a set.
Given a list (ArrayList or LinkedList), convert it into a set (HashSet or TreeSet) of strings in Java. We simply create an list. We traverse the given set and one by one add elements to the list.
In this, we can convert the list items to set by using addAll() method. For this, we have to import the package java. util.
The simplest way to convert List to Set in Salesforce is given below: List<String> tempList = new List<String>(); Set<String> tempSet = new Set<String>(); tempList.
There's two things we'd need here:
ISet<T>
- presumably HashSet<T>
will sufficelong?
to long
- presumably by just ignoring any that are null
So, something like:
var hash = new HashSet<long>();
foreach(var id in testIds) {
if(id.HasValue) hash.Add(id.Value);
}
var request = new someTestModel{ ids = hash};
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With