0

Beginner programmer here.

I have to append strings of file names together and have come up with the following methods:

class ConsLoItem implements ILoItem {
    Item first;
    ILoItem rest;

    ConsLoItem(Item first, ILoItem rest) {
        this.first = first;
        this.rest = rest;
    }

public String images() {
    if (this.rest.equals(new MtLoItem()))
    {
        return this.first.images();
    }
    else
        return this.first.images() + ", " + this.rest.images();
    }
}

and keep getting the same results, with:

", jesse.jpeg, " when I expect "jesse.jpeg".

Any ideas on how to remove the ", " from the beginning and end of the file name?

John
  • 21
  • 1
  • 3

1 Answers1

0

You can change your images method, like so

public String images() {
    if (this.rest.equals(new MtLoItem())) {
        return this.first.images();
    } else { // missed a brace here.
        if (this.first.images().length() > 0) {
          return this.first.images() + ", " + this.rest.images();
        }
        return this.rest.images();
    }
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249