回答編集履歴

2

修正

2022/10/19 04:11

投稿

Zuishin
Zuishin

スコア28675

test CHANGED
@@ -12,18 +12,23 @@
12
12
  https://developer.classpath.org/doc/java/util/AbstractCollection-source.html
13
13
 
14
14
  ```Java
15
- public <T> T[] toArray(T[] a)
15
+ 434: public String toString()
16
- 409: {
16
+ 435: {
17
- 410: int size = size();
18
- 411: if (a.length < size)
19
- 412: a = (T[]) Array.newInstance(a.getClass().getComponentType(),
20
- 413: size);
21
- 414: else if (a.length > size)
22
- 415: a[size] = null;
23
- 416:
24
- 417: Iterator<E> itr = iterator();
17
+ 436: Iterator itr = iterator();
18
+ 437: StringBuffer r = new StringBuffer("[");
25
- 418: for (int pos = 0; pos < size; pos++)
19
+ 438: boolean hasNext = itr.hasNext();
20
+ 439: while (hasNext)
21
+ 440: {
26
- 419: a[pos] = (T) (itr.next());
22
+ 441: Object o = itr.next();
23
+ 442: if (o == this)
24
+ 443: r.append("<this>");
25
+ 444: else
26
+ 445: r.append(o);
27
+ 446: hasNext = itr.hasNext();
28
+ 447: if (hasNext)
29
+ 448: r.append(", ");
30
+ 449: }
31
+ 450: r.append("]");
27
- 420: return a;
32
+ 451: return r.toString();
28
- 421: }
33
+ 452: }
29
34
  ```

1

修正

2022/10/19 04:09

投稿

Zuishin
Zuishin

スコア28675

test CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  https://developer.classpath.org/doc/java/util/AbstractCollection-source.html
13
13
 
14
- > ```Java
14
+ ```Java
15
15
  public <T> T[] toArray(T[] a)
16
16
  409: {
17
17
  410: int size = size();