function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShivaShiva 

How to use hash table?

I have a text and it has merged fields. Instead of using direct string replace, is it possible to use hash table concept? How to do in apex code?

 

Thanks

 

HarmpieHarmpie

The APEX implementation of a hash table is a Map. Example (untested):

 

Map<String,List<Account>> aMap = new Map<String,List<Account>>(); for(Account a : [SELECT Id,Name,BillingCity FROM Account LIMIT 200]) { if(aMap.containsKey(a.BillingCity)) { aMap.get(a.BillingCity).add(new List<Account>{a}); } else { aMap.put(a.BillingCity,new List<Account>{a}); } }

 

 

This populates a hashmap with all accounts per billingcity (billingcity being the hash key).

Message Edited by Harmpie on 05-25-2009 05:28 AM
Message Edited by Harmpie on 05-25-2009 05:29 AM