Pregunta

Tengo mapa con la clave y el valor y mi objetivo es obtener la lista de 'clave'. Me refiero a conseguir que la matriz o lista. Llegado al punto en el que tengo valores clave en el conjunto, pero no han de averiguar cómo convertir a la matriz.

a continuación es mi código:

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 :(
¿Fue útil?

Solución

Utilice el método List.addAll?

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

Si no - se puede bucle siempre de forma manual a través del conjunto ...

Otros consejos

¿Podría utilizar:

Instalar teclas = mmm.keySet (); Lista keyList = nueva lista (teclas);

Siempre debe genéricos utilizados para la seguridad de tipos.

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

Como por enlace: https://salesforce.stackexchange.com/questions/5447/is-there-a-difference-between-an-array-and-a-list-in-apex .

Esta solución va a funcionar.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top