如何将设置设置为Apex中的数组?
-
30-09-2019 - |
题
我的地图具有钥匙和价值,我的目标是获取“键”的列表。我正在考虑将其列入数组或列表。到达集合中有键值的地步,但尚未弄清楚如何转换为数组。
以下是我的代码:
Map<String, String> mmm = new Map<String, String>();
mmm.put('one', 'oneee');
mmm.put('two', 'twooo');
mmm.put('three', 'threeee');
mmm.put('four', 'fourff');
//outputs values in the map
system.debug('=======values()==========>' + mmm.values());
//outputs key in the map
system.debug('=======keyset()===========>' + mmm.keyset());
//get keys in the type SET
SET<string> s = mmm.keyset();
//returns 4
system.debug('------------------------------------' + s.size());
s.arrayTo() //this method does not exist :(
解决方案
采用 List.addAll
方法?
如果没有 - 您总是可以手动循环遍历整个...
其他提示
您可以使用:
设置键= mmm.keyset();列表keyList =新列表(键);
您应始终将仿制药用于类型安全。
Map<String, String> mmm = new Map<String, String>();
mmm.put('one', 'oneee');
mmm.put('two', 'twooo');
mmm.put('three', 'threeee');
mmm.put('four', 'fourff');
List<String> lstKeys = new List<String>(mmm.keyset());
System.debug('Output : '+lstKeys);
该解决方案将起作用。
不隶属于 StackOverflow