Search code examples
javaguava

Convert Iterable to Array using Guava


I need to return a String array. I use Guava to split the String. Please see the code below

Iterable<String> arrayOfValues =  Splitter.on(";").split(myString);

it returns an Iterable. but i need a String[]. Is there are any way to give Iterator< Element > and convert that to Array[]. Many Thanks


Solution

  • Use the Iterables.toArray(Iterable<? extends T> iterable, Class<T> type) method in Guava.