我的地图具有钥匙和价值,我的目标是获取“键”的列表。我正在考虑将其列入数组或列表。到达集合中有键值的地步,但尚未弄清楚如何转换为数组。

以下是我的代码:

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 :(
有帮助吗?

解决方案

其他提示

您可以使用:

设置键= 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);

根据链接: https://salesforce.stackexchange.com/questions/5447/is-there-there-a-difference-between--an-an-aray-and-aray-and-a-list-in-apex .

该解决方案将起作用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top