Dictionary v/s Array? – User friendly Tech help

nWhat is the difference between Dictionary and Array?
n
nSolution:-
n
n1.For using Dictionary, we need to create its object using “CreateObject“, method, while Array is declared like normal variables using “Dim
n
nExample:-
n
Creating Dictionary Object
nSet obj = createobject(“scripting.dictionary”)
n
n‘Declaring array 
nDim arr(0)
n
n
n2.Dictionary is more flexible and is richer in terms of built-in functionality. (It has range of methods and properties like Items, remove, Keys,Exists)
n
nExample:-
n
‘Creating Dictionary Object
nSet obj = createobject(“scripting.dictionary”)
n‘Using Add methods to add values to dictionary object
nobj.Add “UFT”,“2012”
nobj.Add “QTP11”,“2010”
nobj.Add “QTP10”,“2009”
n
n
n3.Dictionaries also work better when you want to locate items by their content rather than their position, so we use item property
n
Example:-
n
‘Locating items in Dictonary
nMsgBox obj.item(“UFT”)
n
n4.Array uses ReDim to vary the size while we don’t need this in  dictionary’s .
n
n‘Declaring array 
nDim arr()
n‘Resizing Array
nReDim arr(1)
narr(0) = “UFT”
narr(1) = “QTP11”
nmsgbox arr(0)n

5.When you delete a particular item from a dictionary, all the subsequent items automatically shifts up
n
n6.Most important of all is that Array can have index only as numeric (0,1,2..) while we can  use keys to identify dictionary items and Keys can be of any data subtype(String,integer), except an array or dictionary.
n
n7.Dictionary can’t be multidimensional like Array’s
n
n
nFor more information on Dictionary object:-
n
nExample Scenario’s
nInterview Questions on Array’s?

Was this article helpful?
YesNo

Similar Posts