You can use a combination of list methods.
//start context
list<string> lst= new list<string>{'aa','bb','cc','dd'};
string var = 'cc';
//find the index of var
integer index;
for(integer i =0;i< lst.size();i++){
if(var==lst[i]) index=i;
}
//may want to throw an exception if index is still null
list<string> tempLst = lst.clone();//backup your collection
lst.clear(); //empty your collection
lst.add(tempLst[index]); //retrieve your desired record and put it on index 0
tempLst.remove(index); //remove your record from the old collection
lst.addAll(tempLst); //add the other data to your list
system.debug(lst); /// |USER_DEBUG|[22]|DEBUG|(cc, aa, bb, dd)
But, logic like this might imply you should consider exploring the apex map collection type and its methods. Know you can use the map.values() property to still reference it as a list, or can directly iterate over a map in Visualforce too.
Answer from Samuel De Rycke on Stack ExchangeMaximum Size of List in APEX Salesforce - Stack Overflow
a tier list for the best characters rn in apex
This guy is trolling.
More on reddit.comWe Ranked Every Apex Team! | TSM ALGS Tier List
Confirmed : Evan Tripods Fanboy. MFAM
More on reddit.comFinally, some demotions! Apex Tier List 2022-12-12
Videos
There's not a defined limit for size of a list. I think the limit you'd eventually hit is heap size, which is currently 12 MB for a batch job. However, you need to be mindful of the number of records you can process via DML, which is currently 10,000.
Two questions combined there.
1) Yes, always do DML statements with a list of objects if you can. This will be executed faster, and will help you to avoid governor limits. (you should really check them out if you haven't)
2) edit: Used to be 1K few years ago, now it's just a heap size as Jeremy writes. You still have 1K for collection passed to visualforce though (10K if it's a page with readonly="true") and max 50K rows returned in all queries