Z`List Operation in Apex
I am going to show you how to do operation like (Add(), sort(),addall(), clear(),clone) in a list.
Developer Console
Apex List and Method
-
- List<Integer> IntList = new List<Integer>();
- IntList.add(4);
- IntList.add(6);
- IntList.add(0,8);
- IntList.add(1,9);
- IntList.sort();
- For(Integer c:IntList)
- {
- System.debug(c);
-
- }
-
-
- List<Integer> IntList=new List<Integer>();
- IntList.Add(2);
- List<Integer> IntList2=new List<Integer>();
- IntList2.Add(3);
- List<Integer> IntListMaster=new List<Integer>();
- IntListMaster.addAll(IntList);
- IntListMaster.addAll(IntList2);
- IntListMaster.sort();
- For(Integer DD:IntListMaster)
- {
- system.debug(DD);
- }
Find here the debug result.
-
- List<Integer> IntList=new List<Integer>();
- IntList.Add(2);
- List<Integer> IntList2=new List<Integer>();
- IntList2.Add(3);
- List<Integer> IntListMaster=new List<Integer>();
- IntListMaster.addAll(IntList);
- IntListMaster.addAll(IntList2);
- IntListMaster.clear();
- List<Integer> IntList3=new List<Integer>();
- IntList3.Add(5);
- IntListMaster.addAll(IntList3);
- IntListMaster.sort();
- For(Integer DD:IntListMaster)
- {
- system.debug(DD);
- }
Find here the debug result.
- List<Integer> IntList=new List<Integer>();
- IntList.Add(2);
- List<Integer> IntList2=new List<Integer>();
- IntList2.Add(3);
- List<Integer> IntListMaster=new List<Integer>();
- IntListMaster.addAll(IntList);
- IntListMaster.addAll(IntList2);
- IntListMaster.clear();
- List<Integer> IntList3=new List<Integer>();
- IntList3.Add(5);
- IntListMaster.addAll(IntList3);
- IntListMaster.sort();
- List<Integer> IntListMaster1=new List<Integer>();
- IntListMaster1=IntListMaster.clone();
- system.debug(IntListMaster1.size());
- For(Integer DD:IntListMaster1)
- {
- system.debug(DD);
- }