-2

I have imported that library:

import org.apache.commons.codec.binary.StringUtils;

And tried to use some of methods, but failed:

StringUtils.isNumeric("2398sdf");

IDE keep saying me that, method is undefined. What is wrong here?

Rocketq
  • 5,423
  • 23
  • 75
  • 126
  • 1
    Well what makes you think it *should* be present? I can't see it in the documentation: https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/StringUtils.html – Jon Skeet Mar 01 '16 at 09:05
  • 1
    Did you download the jar with StringUtils ? .. See http://stackoverflow.com/questions/8660151/how-do-i-use-stringutils-in-java – DTH Mar 01 '16 at 10:55

2 Answers2

3

You're using the wrong StringUtils class. You're importing org.apache.commons.codec.binary.StringUtils, but it looks like you want org.apache.commons.lang.StringUtils or org.apache.commons.lang3.StringUtils. The first of these doesn't have an isNumeric method, whereas both of the lang-based ones do.

Obviously this means you'll need the "commons lang" library to be in your classpath. (Which class you import will depend on which version you use.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

The StringUtils.isNumeric method is defined in the package org.apache.commons.lang3 and not in the one you specified.

Robert Kock
  • 5,795
  • 1
  • 12
  • 20