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.
You have an older version of commons-lang. Get the latest version, which has this method.
Alternatively, you can call StringUtils.join(friendsList.toArray(), ',')
"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).
An issue with classpath I guess.
This method exists since commons lang 2.3, check your jar.
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