Example Programs using Set, Apex & Visual force
Write an apex class to add list of elements to setPublic class set example
{
Public set <string> name {get; set;};
Public set example ()
{
List <string> my list = new list <string> ()
My list. add (‘sushi’);
My list. add (‘sushi’);
My list. add (‘Rakesh’);
My list. add (‘Rakesh’);
names = new set <string> ();
names. add (‘one’);
names. add (‘two’);
names. add (‘one’);
names. add (‘one’);
names. add (my list);
}
}
Public void retains all (list) // this will keep only the values that are existing in list and set.
Remove rest of the value.
Public class set example
{
Public set <string> names {get; set;};
Public Boolean test {get; set;}
Public set example ()
{
List <string> my list = new list <string>();
Mylist.add(‘sashi’);
Mylist.add(‘ram’);
Mylist.add(‘kumar’);
test = names.retainAll(mylist);
}
}
Visual force Page :
<apex:page controller = “setExample”>
<apex:pageBlock>
<apex:datalist value =”{!names}” var =”a”>{!a}
</apex: datalist>
</apex: pageBlock>
</apex:page>
No comments:
Post a Comment