Java 在不同的计算机上返回不同的字符串比较结果

Java returning different results for string comparisons on different computers

我现在正在开发一个小程序,它的一个功能是从数据库中读取一组字符串并将其与同一个 table 中的另一个字符串进行比较。如果它们相同,则只显示一个字符串,如果它们不同,则显示两个字符串。

在我的开发机器上,这按预期工作。当我在客户的测试计算机上安装应用程序时,过程表现不同。具体来说,字符串 return 在我的计算机上是相同的,但它们在我客户的计算机上经常 return 不同。

这个代码很简单:

if (!item.getDescription().equals(item.getBackDescription())) {
        item.setDescriptionDisplay(item.getDescription() + "   (" + item.getBackDescription() + ")");
    } else {
        item.setDescriptionDisplay(item.getDescription());
}

这是它发生的截图(我的电脑在上面):

我为此想到并尝试了几种方法:

其他说明:

任何帮助将不胜感激,我已经弄乱了好几个小时。谢谢

您是否尝试过删除一些空格?尝试:

if (!item.getDescription().trim().equals(item.getBackDescription().trim())) {
        item.setDescriptionDisplay(item.getDescription() + "   (" + item.getBackDescription() + ")");
    } else {
        item.setDescriptionDisplay(item.getDescription());
}