Java returns different results for comparing strings on different computers

Now I am working on a small program, and one of its functions is to read a set of rows from the database and compare it with another row in the same table. If they are the same, they simply represent one line; if they are different, it represents both lines.

On my development machine, this works as expected. When I install the application on a client test computer, the process behaves differently. In particular, strings are returned as the same on my computer, but they are often returned as different on my client computer.

The code for this is simple:

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

Here's a screenshot (my computer is on top):

From my computer from your computer

I thought and tried several things for this:

  • I associate the JRE with the application, their computer is not installed. I have JRE installed on my computer. If you have problems or a difference with one of the versions, I deleted the JRE (and JDK) on my computer to make sure that it uses the bundled version in my copy of the application.

  • I wondered if there was a problem with the data that I used to test on my computer. I exported the tables that I use to create their machine and read them in my copy of the database to make sure the data is the same.

Other notes:

  • Data is not always erroneous on their computer. What should be marked as different, but not everything that should be marked the same, is incorrectly marked.

Any help would be greatly appreciated, I have been tinkering with it for many hours. Thanks.

+4
source share
1 answer

Have you tried to remove spaces? Try:

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

All Articles