Question

The following code should work, since join accepts an iterator as argument:

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

…

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

Alas, it doesn’t. Can somebody explain to me why?

Was it helpful?

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top