To string on a collection can get into a infinite loop if somewhere in the graph of collected items is a reference back to itself. See example below.
Yes, good cod
You can create toString which takes an identity hash set.
public String toString() { return toString(Collections.newSetFromMap(new IdentityHashMap())); } private String toString(Set seen) { if (seen.add(this)) { // to string this } else { return "{this}"; } }