List, Set and Map-2

14. What is Set? 
A. Set: It is an unordered collection of similar elements where the memory size can grow or reduce dynamically based on 

Dynamic requirement.
Collection or Group of primitive/Non–primitive data types
The elements in the set are not reserving insertion order.
Syntax: Set<Datatype> setname;

15.What is the internel datastructure?
A. Set<primitive/non-primitive type>  setinstance = new set<primitive/non-primitive type> ();

16. Will Set allow the duplicates?
A: No, Set will not accept duplicate values.

17. Will the set maintain insertion Order?
A:  No, the elements in the Set are not reserving insertion order.

18. How the elements in the set are referred?
A: Set Key Word

19. What is the use of contains(ele), ContainsAll(ele)?
A: Contains (ele): This method will check whether the given element is in the set.
         If it is in the set then returns true.
        Set<Integer> ages=new Set<Integer>{12,22,33,44};
          Boolean b=ages.Contains(33); // true
     ContainsAll(): This method will check whether the given List|set of elements are in the Set.
             Set<integer> ages=new Set<Integer>{12,20,30};
            Set<Integer> values=new Set<integr> {20,30};
                Boolean b=ages.ContainsAll(Values);

20. What is the use of retainAll(ele)?
A: retainAll(): Retains only the elements in this set that are contained in the specified list.
          Syntax:
                           Set<integer> mySet = new Set<integer>{1, 2, 3};
                          List<integer> myList = new List<integer>{1, 2, 4, 3};
                          Boolean result = mySet.retainAll(myList);
                          System.assertEquals(true, result);

21. Can we sort the values in the set? 
A:No, we can’t, bcz internally arrange the values in ascending order.

22. What is Map?
A: Map: Map is a Collection of Key-Value pair where key should unique and value can be duplicate.
First datatype is key and it allows primitive datatypes and should be unique.
Second datatype is values and it allows both primitive & non-primitive datatypes and allows duplicates.
          Syntax: Map<Key, Value> mymap;

23. Can a key be duplicate?
 A: No, Key should be Unique in Map.

24. Can a Value be a duplicate?
 A: Yes, value can be duplicate in Map.

25. What is Keyset() in map?
A: KeySet(): Retrieves all the keys and return type is set;
             map.keySet();

26. What is values() on Map?
A:  values(): Returns a list that contains all the values in the map.
       map.values();

Comments

  1. Useful blog admin, the way you have clearly explained about salesforce. This is really helpful to me.Keep up the good work and share more like this.
    Salesforce Training Institutes in Chennai | Salesforce Course in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Page Layouts

SOQL Scenario-1