Esempio n. 1
0
  /** Returns a comma separated string of the worm names */
  public String getCommaSeparatedNames() {

    String names = "";
    int size = getWorms().size();

    for (Worm worm : getWorms()) {
      if (getWorms().get(size - 1).equals(worm)) {
        names += worm.getName();
      } else {
        names += worm.getName() + ", ";
      }
    }

    return names;
  }
Esempio n. 2
0
  /** Returns a unique list of names separated by commas */
  public String getUniqueCommaSeparatedNames() {

    Set<String> names = new HashSet<>();
    for (Worm worm : getWorms()) {
      names.add(worm.getName());
    }
    String result = "";
    Iterator<String> it = names.iterator();
    while (it.hasNext()) {
      result += it.next();
      if (it.hasNext()) {
        result += ", ";
      }
    }
    return result;
  }