Sunday, 16 June 2013

Map usage in Apex

Map usage in APEX:

public with sharing class MapUsage {
        
        public static void mapUse(){
        
            Map<Integer, String> mp = new Map<Integer, String>();
            // kEy is Integer
            // value is String
            
            mp.put(1221,'Mahi');
            //mp.put(1226,'Shyam');
            mp.put(1211,'Rajesh');
            mp.put(1255,'Kiran');
            
            System.debug('---------------Elements in the map are ------------>'+mp);
            System.debug('---------------Size of the map is-------4---------->'+mp.size());
            System.debug('------------Keys in the map are ----------->'+mp.keyset());
            System.debug('------------Values in the map are ----------->'+mp.values());
            
            System.debug('------------------'+mp.get(1211));
            
            mp.remove(1226);
            
            mp.put(1211,'Charan');
            mp.put(1248,'Pavan');
            mp.put(1222,'Kiran');
            
            System.debug('---------------Elements in the map are ------------>'+mp);
            System.debug('---------------Size of the map is-------5---------->'+mp.size());
            
            for(Integer i : mp.keyset()){
                System.debug('-----Key--------'+i);
                System.debug('-----value---------'+mp.get(i));
            }
            
            for(String s: mp.values()){
                System.debug('----------------'+s);
            }
            
        }        
}

2 comments:

  1. - Contains keyword allow unique values
    - keys are case sensitive
    - can hold null value
    - put method
    - 4 nested levels overall 5 levels
    - no sort() method
    - unordered
    - duplicate key replaces with old one
    - Map myStrings = new Map{'Jan'=>'1','Feb'=>'2','March'=>'3'}

    ReplyDelete
  2. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
    Sales Fore CRM Training in Chennai

    ReplyDelete

Labels