Domanda

Ho mappa con la chiave e il valore e il mio obiettivo è quello di ottenere l'elenco dei 'chiave'. Sto pensando di farlo alla matrice o elenco. Ha ottenuto al punto in cui ho i valori chiave del set, ma non ho capire come convertire alla matrice.

sotto è il mio codice:

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 :(
È stato utile?

Soluzione

Utilizzare il metodo List.addAll?

http: //www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_list.htm?SearchType=Stem

In caso contrario - si potrebbe ciclo sempre manualmente attraverso il set ...

Altri suggerimenti

Potreste usare:

Set chiavi = mmm.keySet (); Lista keylist = nuova lista (tasti);

Si dovrebbe sempre utilizzato farmaci generici per la sicurezza tipo.

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

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

Questa soluzione funziona.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top