-2

I have 2 java lists

ArrayList<String> list1 = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();

I load some data from the database to the first one and from diffrent database to the second one.

The strings in the lists look exactly the same:

3441134 China Ap F
3441134 China Ap F

But when I check:

if(list1.get(1).equals(list2.get(1))){
logger.info("true");
}
else{
logger.info("false")
}

I always get

false

Can somebody say why? I checked white spaces and it's the same too.

EdXX
  • 872
  • 1
  • 14
  • 32

1 Answers1

1

I think is something related with character encoding, you may be seeing the same string in console and debug but internally they have a extra invisible byte because of the encoding.

Try to look at: Invisible characters in Java Strings you will understand what i am saying.

justcode
  • 1,562
  • 3
  • 14
  • 25