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
Ashok S 7Ashok S 7 

how to find the size of set

Hai guys,
my requirment is calculate the size of set
vf page
------------------
<apex:page controller="SetExample_Controller">
  <apex:pageblock >
  <apex:pageBlockTable value="{!names}" var="v">
  <apex:column value="{!v}"/>
  </apex:pageBlockTable>
  </apex:pageblock>
</apex:page>

controller
---------------------
public class SetExample_Controller 
{
  public set<string> names{get;set;}
  public SetExample_Controller()
  {
     names = new set<string>();
     names.add('one');
     names.add('two');
     names.add('sam');
     names.add('one');
     names.add('one');
     
  }
  public Integer size()
  {
     Integer mysize = names.size();
  
     return mysize;
  } 
}

plesae help me
Best Answer chosen by Ashok S 7
Amit Chaudhary 8Amit Chaudhary 8
If you want to use in Class you can try below code

names.size()

You want to use in VF page you can try like below

<apex:pageBlockTable value="{!names}" var="v" rerender="{!if(names.size > 0 , true,false)}">

Please let us know if this will help you

Thanks,
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
If you want to use in Class you can try below code

names.size()

You want to use in VF page you can try like below

<apex:pageBlockTable value="{!names}" var="v" rerender="{!if(names.size > 0 , true,false)}">

Please let us know if this will help you

Thanks,
Amit Chaudhary
This was selected as the best answer
Ulas KutukUlas Kutuk
Try name.size no parenthesis
Alon WaismanAlon Waisman

Just a heads up that the above solution doesn't actually work. That's only good for Lists. Looks like Visualforce doesn't allow .size for a Set. One actual solution for this is to setup a proxy variable, like this:

 

public Integer name_count {get {return names.size();}}