You have declared paint
as a String (and not a List of Strings) here.
public String paint;
And then you convert the String variable to a List.
List words = Arrays.asList(paint);
Which is why the list words
has only the single String which was added last with house1.addPaint()
, which just assigns the String this.paint = paint;
inside it.
There are many ways you can fix it. But I'll tell the one that requires the least amount of changes.
My suggestion:
public void addPaint(String paint) {
paints.add(paint);
}
and
List words = Arrays.asList(paints);