File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "String Problem." Watch "String Problem." New topic
Author

String Problem.

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 206
Hi Guys ,

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


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
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Problem.
 
Similar Threads
Again in Problem with equals()
StringBuffer and String doubt
Boxing, == and equals
Wrapper Classes Autoboxing Concept
Can someone help me with this