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
To make an array iterable either you need to convert it to a stream or as a list using the asList() or stream() methods respectively. Then you can get an iterator for these objects using the iterator() method.
partition. Divides an iterable into unmodifiable sublists of the given size (the final iterable may be smaller).
Use the Iterables.toArray(Iterable<? extends T> iterable, Class<T> type)
method in Guava.
If you use the plain Java String.split(regex) method, you're fine. It returns a String[].
"my;string".split(";") String[] splits = mystring.split(";");
Don't use fancy libraries if you don't need them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With