質問

joinは、引数としてイテレータを受け入れるため、次のコードが機能します。

import static org.apache.commons.lang.StringUtils.join;
import java.text.StringCharacterIterator;

…

join(new StringCharacterIterator("A String"), " ");
.

AlAs、そうではありません。誰かが私に説明するのはなぜですか?

役に立ちましたか?

解決

According to the documentation, StringCharacterIterator inherits from and only from CharacterIterator. A CharacterIterator does not inherit from a generic Iterator, which is what join wants.

http://download.oracle.com/javase/1.4.2/docs/api/java/text/CharacterIterator.html

他のヒント

First of all, the join method takes two arguments : an iterator and a separator string or char.

And if you look at the javadoc of StringCharacterIterator, you'll see that this class does not implement java.util.Iterator.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top