public with sharing class ListUsage {
public void listUse(){
// Initialising a list
List<String> lst = new List<String>();
// Adding elemenst into list
lst.add('ABC');
lst.add('DEF');
lst.add('GHI');
lst.add('JKL');
System.debug('---------Elements in the list are-------------->'+lst);
System.debug('----------Size of the Elements are-----4-------->'+lst.size());
System.debug('-----------Element in 2nd index--------GHI-------->'+lst[2]);
lst.remove(1);
System.debug('---------Elements in the list after removing are-------------->'+lst);
System.debug('----------Size of the Elements after removing are----3--------->'+lst.size());
lst.add('MNO');
lst.add('GHI');
lst.add('DEF');
lst.add('1248');
System.debug('---------Elements in the list after adding duplicate values are-------------->'+lst);
System.debug('----------Size of the Elements after adding duplicate values are--------7----->'+lst.size());
List<String> newlst = lst.clone();
System.debug('---------Elements in the new list are-------------->'+newlst);
System.debug('----------Size of the Elements in new list are-------7------>'+newlst.size());
lst.clear();// removes all the elements in the list
System.debug('-----------------List is Empty or not-------true----------->'+lst.isEmpty());
System.debug('-----------------New List is Empty or not-------false----------->'+newlst.isEmpty());
//Indexing for loop
for(integer i=0; i<newlst.size(); i++){
System.debug('-----Index------->'+newlst[i]);
}
//For Each Loop
for(String s: newlst){
System.debug('-----For Each---------->'+s);
}
}
}
Sunday, December 18, 2022
List usage in Apex
Subscribe to:
Post Comments (Atom)
-
Beginner-Level Questions 1. What is MuleSoft, and what are its key features? Answer : MuleSoft is an integration platform that enables dev...
-
As a Salesforce Admin, Salesforce flows are one of the most effective ...
-
In this session/post we will learn about Integration Procedure Basics and learn about declarative server side processing in OmniStudi...
No comments:
Post a Comment