Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use Apache's StringUtils.join on a List?

When I try

StringUtils.join(myList,',');

I get a compilation failure:

cannot find symbol
symbol  : method join(java.util.List,char)

But the following works:

StringUtils.join(myList.toArray(),',');

The docs (Apache Commons Lang 2.5) seem to indicate that both should work, as they record both:

public static String join(Collection collection,
                      char separator)

and

public static String join(Object[] array,
                      char separator)

Any ideas? For the record, I'm importing import org.apache.commons.lang.StringUtils;

like image 978
Eric Wilson Avatar asked Aug 23 '11 17:08

Eric Wilson


2 Answers

The most probable reason is, that you are using an older version of Commons Lang, since the method using a Collection has only been added in 2.3.

You can check that by looking in the MANIFEST.MF file in the Jar at the Implementation-Version field.

like image 147
nfechner Avatar answered Sep 22 '22 10:09

nfechner


I had the problem earlier and realized it is due to the order of my import.

Once I shifted my commons JAR up the order of import, it works.

Hope this helps.

like image 34
Phoebe Chan Avatar answered Sep 23 '22 10:09

Phoebe Chan