Is there a more efficient way to create a string array from Guava’s Splitter than the following?
Lists.newArrayList(splitter.split()).toArray(new String[0]);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Probably not so much more efficient, but a lot clearer would be
Iterables.toArray(Iterable, Class)This pretty much does what you do already:
By using the
collection.size()this should even be a tick faster than creating a zero-length array just for the type information and havingtoArray()create a correctly sized array from that.