I has tried this and i feel that the output is contradictory to my thinking. equals method checks to see if the String literal is "meaningfully equivalent" . Based on that , I wrote a small program to check it. Here's it.
can you tell me why it goes to else block , when yogendra and Yogendra both does are "MeaningFully Equivalent". This has been nailing me. Please help.
Thanks in Advance.
Yogendra Joshi.
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Scott Johnson
Ranch Hand
Joined: Aug 24, 2005
Posts: 518
posted
0
These two strings are not equal because the first character is different. "Y" does not equal "y".
If you want to do a non-casesensitive comparison use this:
Yogendra Joshi
Ranch Hand
Joined: Apr 04, 2006
Posts: 206
posted
0
Hi Scott ,
Thanks for your immediate reply. I tested and it worked !
Is there any workaround rather then using equalsIgnoreCase ?
Thanks.
Yogendra Joshi.
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
posted
0
Is there any workaround rather then using equalsIgnoreCase?
a.toLowerCase().equals(b.toLowerCase()), and a.toUpperCase().equals(b.toUpperCase()).
I do not think you want to use them instead of equalsIgnoreCase.