7

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;

Michael Easter
  • 23,733
  • 7
  • 76
  • 107
Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
  • 3
    It's available since version 2.3. Do you have an outdated JAR file? – home Aug 23 '11 at 17:18
  • I actually have the same problem but i've checked everything and my versions 2.6 – Kevin Aug 24 '11 at 16:24
  • have you tried myList.iterator? – Kevin Aug 24 '11 at 16:25
  • @Kevin My issue was the version of apache-commons in my project. If you are having the same symptoms with version 2.6, you may want to ask your own question. (This question, with an accepted answer, is not likely to receive more attention.) – Eric Wilson Aug 24 '11 at 16:39

3 Answers3

12

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.

nfechner
  • 17,295
  • 7
  • 45
  • 64
2

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.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
0

Not quite your problem but related:

In org.apache.commons.lang.StringUtils, there exists a method

join(Object[])

That doesn't take a delimiter.

join(Object[], char)
join(Collection, char)

All take delimiters (may use String instesad of char). So if you forget the delimiter, your error message may be pointing to the wrong problem.

djechlin
  • 59,258
  • 35
  • 162
  • 290