Hi guys, Today we see all the collection classes with examples.
- List
- Set
- Map
- Array
- Struct
List:
Key words:
myList.addEnd(string);//Adds value to end of the list
myList.addStart(string);//Adds value to the beginning of the list
myList.appendList(myList1);//Adds elements myList1 to the end of current list.
myList.elements();//Returns the number of items in the list
myList.getEnumerator();//This will returns an enumerator to get the values form list.
myList.toString();//This is convert list into string.
Container = myList.pack();// Pack the list into a container
List myList = con2List(Container);// Convert container
// Insert data into List
List myList;
TempTable rmpLoc;
myList = new List(Types::Record);
for (tmpLoc = getFirstSelection(TmpTable_ds); tmpLoc ; tmpLoc = TmpTable_ds.getNext())
{
myList.addStart(iRBApprovalTmpLoc); // myList.addEnd(iRBApprovalTmpLoc);// add the data at end.
}
myList.elements(); // return number of elements
into list.
// Get data from List
ListIterator:
ListIterator literator = new ListIterator(myList);// my list
while (literator.more())
{
tmpTable.data(literator.value());
} ListEnumerator:
ListEnumerator enumerator = myList.getEnumerator();
while(enumerator.moveNext())
{
iRBApprovalTmp.data(enumerator.current());
}
Combine two lists into single list:
List myList = new List(Types::String);
List Newlist = new List(Types::String);
List combinedList = new List(Types::String);
combinedList = List::merge(myList, Newlist);
print combinedList.toString();
Set:
Key words:
set records = new set(Types::);
records.add(value);// Add value to the set
records.empty();// Check set is empty or not
records.elements();//Returns the number of value in the set
records.in(value);// it Checks the value is present in set or not.
records.remove(value);// Remove the value from set.
records.getEnumerator();// It getthe enumerator and will return the values i set.
records.pack();//Convert into container.
Set::difference(_set1, _set2);//Returns items that are in _set1 but are not in _set2
Set::intersection(_set1, _set2);// Duplicated values are returend.
Set::union(_set1, _set2);//Combine the all the elements of _set1 and _set2
// Insert data into Set
Set records = new Set(Types::Int64);
Notes values;
container packed;
;
records.add(tmpLoc.Recid);
records.add(tmpLoc.Recid);
// If you want conevert set to container
packed = records.pack();
values = con2Str(packed, ',');// convert container to string
// Get data from Set
SetIterator recordsIterator;
//recordsIterator = new SetIterator(
Set::create(packed));// If you using container we
//can follow like this
recordsiterator = new setiterator(records);
while (recordsiterator.more())
{
info(strfmt('%1',recordsiterator.value());
recordsiterator.next();
}
Map:
Key Words;
Map myMap = new Map(Types::Integer, Types::String);
myMap.remove(key);//Remove the value from map.
myMap.elements();//Returns the number of key-value pairs in the map
myMap.exists(key);//Returns true if _key is present in the map.
myMap.insert(1,'Hi');// Insert record.
myMap.lookup(Key);//Returns the corresponding value of _key.// Insert data into Map
Map myMap;
myMap = new Map(Types::Integer, Types::String);
myMap.insert(1, 'Test1');
myMap.insert(2, 'Test2');
myMap.insert(1, 'Test3');//Previous Test1 value overwritten with Test3.
// Get data from Map
MapEnumerator mapEnumerator;
mapEnumerator = myMap.getEnumerator();
while (mapEnumerator.moveNext())
{
info(strfmt("key %1 value %2",
mapEnumerator.currentKey(),
mapEnumerator.currentValue()));
}
For struct and array check below link.
Keep Daxing!!
No comments:
Post a Comment