New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Sunday, 16 June 2013

Set usage in Apex

Set usage in APEX:

public with sharing class SetUsage {
    
    public void setUse(){
        
        Set<Integer> st = new Set<Integer>();
        
        st.add(1234);
        st.add(1248);
        st.add(1225);
        st.add(1252);
        
        System.debug('----------------Elementa in the set are --------------'+st);
        System.debug('----------------Size of Elementa in the set are ------4--------'+st.size());
        
        st.remove(1252);
        System.debug('----------------Size of Elementa after removing an element in the set are ------3--------'+st.size());
        
        
        st.add(1248);
        st.add(1252);
        st.add(1221);
        System.debug('----------------Size of Elementa in the set after adding duplciates are ------5--------'+st.size());      
        
        Set<Integer> newst = st.clone();
        System.debug('----------------Size of Elementa in the new set are -------5-------'+newst.size());
        
        st.clear();
        System.debug('-----------------NEw set is EMpty or not--------false--------'+newst.isEmpty());
        
        for(Integer i: newst){
            System.debug('----------------->'+i);
        }        
    }
    
}

1 comment:

  1. - Contains keyword allow unique values
    - It is case sensitive
    - addAll method
    - 4 nested levels overall 5 levels
    - no sort() method
    - unordered

    ReplyDelete

Labels