<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
import org.apache.commons.collections4.Transformer;
import org.apache.commons.collections4.TransformerUtils;
import org.apache.commons.collections4.collection.TransformedCollection;
public class ArrayExample {
public static void main(String[] args) {
String[] array = {"apple", "banana", "orange"};
Transformer<String, String> transformer = TransformerUtils.invokerTransformer("toUpperCase");
TransformedCollection<String, String> transformedCollection = TransformedCollection.transformedCollection(Arrays.asList(array), transformer);
for (String element : transformedCollection) {
System.out.println(element);
}
}
}
APPLE
BANANA
ORANGE
import org.apache.commons.collections4.Transformer;
import org.apache.commons.collections4.TransformerUtils;
import org.apache.commons.collections4.IteratorUtils;
public class IteratorExample {
public static void main(String[] args) {
List<String> list = Arrays.asList("APPLE", "BANANA", "ORANGE");
Iterator<String> iterator = list.iterator();
Transformer<String, String> transformer = TransformerUtils.invokerTransformer("toLowerCase");
Iterator<String> transformedIterator = IteratorUtils.transformedIterator(iterator, transformer);
while (transformedIterator.hasNext()) {
System.out.println(transformedIterator.next());
}
}
}
apple
banana
orange