7

I have an ArrayList that i would like to join with a delimiter of ',', i read in some answers here that StringUtils.join is a good option but the problem is that when i try to join an ArrayList i get the following error:

java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.join(Ljava/util/Collection;C)Ljava/lang/String;

code:

ArrayList<String> friendsList = new ArrayList<String>();
.
.
.
StringUtils.join(friendsList, ',');

what am i missing ?

when i'm coding with netbeans it does not alert me of this error, it happens only when I try to compile.

5 Answers 5

18

You have an older version of commons-lang. Get the latest version, which has this method.

Alternatively, you can call StringUtils.join(friendsList.toArray(), ',')

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this answer, I was pulling my hair out over this one.
2

"it happens only when I try to compile."

This is not a compilation error. It's a linkage error that happens at runtime when the signature of the method being invoked does not match the one of the relevant class in the classpath. You probably have different jars at compile time and runtime (different versions maybe).

1 Comment

Hi sorry for waking up so late, I am also having the same issue, I checked by printing the System.getProperty("java.class.path") that it is having the commons-lang-2.5 in it, but still I am having this error during runtime, any clue?
1

An issue with classpath I guess.

Comments

1

This method exists since commons lang 2.3, check your jar.

Comments

1

I use 2.4.jar. Still I had to use something like this StringUtils.join(friendsList.toArray(), ',') to get it done.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.