0

I have a string that contains value "001" that I need to evaluate as a string, however java keeps evaluating as an integer. Here is my simple sample code:

String equipmentCode = "001";

boolean questionable = StringUtils.equals(EquipmentCode,"???");
boolean emptyStuff = StringUtils.isNotEmpty(EquipmentCode);

if (questionable == false && emptyStuff == true) {
    return true;
} else {
    return false;
}

This fails on the StringUtils.equals line since it's evaluating EquipmentCode as an int. How can I ensure it's evaluated as a string? tia

Basil Battikhi
  • 2,638
  • 1
  • 18
  • 34
  • 6
    Don't capitalise your variable names. What you're describing is impossible if you are using StringUtils. There does not exist an integer override of the `equals` method in the 3.7 version of that class. And you declare the type of `equipmentCode` as String. – ifly6 Jul 18 '18 at 15:23
  • Which StringUtils class are you using? Apache Commons? – Cecilya Jul 18 '18 at 15:24
  • 1
    Java will not evaluate Equipmentcode as an `int` in the given code. You may need to show the inputs and outputs (including exact error messages, if any) that lead you to think that's what is happening. – Mark Adelsberger Jul 18 '18 at 15:24
  • 1
    Print the type of EquipmentCode here and there to help you debug this error. I am pretty confident that variable is not changing into an int. – Rob Jul 18 '18 at 15:25
  • Using StringUtils https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html – codeMonkeySeedoo Jul 18 '18 at 15:47
  • Thanks for your suggestions. So I just noticed an error received that "Error in method invocation: Static method equals(java.lang.Integer, java.lang.String) not found in class'org.apache.commons.lang3.StringUtils'" so I think I understand the problem. Thanks! – codeMonkeySeedoo Jul 18 '18 at 15:57
  • Just to follow up on this - the interpreter used was taking the string '001' and converting it into an integer. It had to be overridden using proprietary code to utilize this value as a string. – codeMonkeySeedoo Jan 21 '19 at 14:26

0 Answers0