Returns the string representation of this Collection. The presentation has a specific format. It is enclosed by square brackets ("[]"). Elements are separated by ', ' (comma and space). @return the string representation of this Collection.
()
| 371 | * @return the string representation of this {@code Collection}. |
| 372 | */ |
| 373 | @Override |
| 374 | public String toString() { |
| 375 | if (isEmpty()) { |
| 376 | return "[]"; //$NON-NLS-1$ |
| 377 | } |
| 378 | |
| 379 | StringBuilder buffer = new StringBuilder(size() * 16); |
| 380 | buffer.append('['); |
| 381 | Iterator<?> it = iterator(); |
| 382 | while (it.hasNext()) { |
| 383 | Object next = it.next(); |
| 384 | if (next != this) { |
| 385 | buffer.append(next); |
| 386 | } else { |
| 387 | buffer.append("(this Collection)"); //$NON-NLS-1$ |
| 388 | } |
| 389 | if (it.hasNext()) { |
| 390 | buffer.append(", "); //$NON-NLS-1$ |
| 391 | } |
| 392 | } |
| 393 | buffer.append(']'); |
| 394 | return buffer.toString(); |
| 395 | } |
| 396 | } |