Accepted answer

I have found the cause of this particular problem. Apparently when processing strings on Macintosh, \r is added in addition to any line breaks. Even though line break characters don't print out on a console, they're still inside the string.

The remedy was to do the following: .trim.replaceAll("\r", "")

And now both strings match.

Related Query

More Query from same tag