문제

I have map with key and value and my goal is to get list of 'key'. I am thinking to get it to the array or List. Got to the point where I have key values in the SET but haven't figure out how to convert to the array.

below is my code:

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 :(
도움이 되었습니까?

해결책

다른 팁

Could you use:

Set keys = mmm.keySet(); List keyList = new List(keys);

You should always used generics for type safety.

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);

As per link : https://salesforce.stackexchange.com/questions/5447/is-there-a-difference-between-an-array-and-a-list-in-apex .

This solution will work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top