Question

Le code suivant devrait fonctionner, car join accepte un itérateur comme argument:

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

…

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

hélas, ça ne le fait pas.Quelqu'un peut-il m'expliquer pourquoi?

Était-ce utile?

La solution

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top