mbrc
mbrc

Reputation: 3963

how to get value from Set<>

 /**
     * @return Returns the parameters.
     */
    public Set<FeatureParameterDTO> getParameters() {
        return this.parameters;
    }

how can i get value from getParameters? toString is not ok? What is correct way?

Upvotes: 1

Views: 39361

Answers (2)

Jonathan Ramos
Jonathan Ramos

Reputation: 180

You possibly have multiple values. So you'd have to iterate over them. You should be more precise with your questions. This one is quite vage. Just a quick example:

import java.util.Set;
import java.util.TreeSet;


public class SetTest {

Set<Integer> parameters = new TreeSet<Integer>();

  public static void main(String[] args) {
      SetTest st = new SetTest();
      Set<Integer> param = st.getParameters();
      param.add(1);
      param.add(2);
      param.add(3);

      for (Integer myVal : param) {
        System.out.println(myVal);
      }
   }

   public Set<Integer> getParameters() {
      return this.parameters;
   }
}

Upvotes: 5

gefei
gefei

Reputation: 19816

You can iterate over the return value of getParameters(), like this:

for (FeatureParameterDTO fpt : getParameters()) {
  // do what you want with fpt
}

Upvotes: 3

Related Questions