Returns a string representation of {@code iterator}, with the format {@code [e1, e2, ..., en]}. The iterator will be left exhausted: its {@code hasNext()} method will return {@code false}.
(Iterator<?> iterator)
| 288 | * The iterator will be left exhausted: its {@code hasNext()} method will return {@code false}. |
| 289 | */ |
| 290 | public static String toString(Iterator<?> iterator) { |
| 291 | StringBuilder sb = new StringBuilder().append('['); |
| 292 | boolean first = true; |
| 293 | while (iterator.hasNext()) { |
| 294 | if (!first) { |
| 295 | sb.append(", "); |
| 296 | } |
| 297 | first = false; |
| 298 | sb.append(iterator.next()); |
| 299 | } |
| 300 | return sb.append(']').toString(); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Returns the single element contained in {@code iterator}. |