function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sagar SharmaSagar Sharma 

How can I get subList of a List in Apex?

I have got a list of SObjects having N number of items/sObjects

SObject[] sList = [sobject1, sboject2, sboject3, ........ , sobjectN];

How can I get just 10 items from the begining of the list

Thanks in advance!
Vamsi KrishnaVamsi Krishna
Sagar
I m not sure if there is an easy & short way.. but looping the original list and getting the top 10 items into a seperate list is an option

SObject[] subList = new List<SObject>();
for(Integer a = 0; a < 10; a++){
  subList.add(sList[a]);
}
Shailesh Patel 7Shailesh Patel 7
how can i do for so many sublist ? can we develope dynamic it?