Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

What easier than comparing 2 one character strings?

807600Oct 17 2007 — edited Oct 18 2007
What easier than comparing 2 one character strings?
But, I can't do it!

I've declared String t which prints out as "A".
if ( t=="A") doesn't give a true value.
If I declare a String initialized to "A", that doesn't fire either.
t.equals("A") gives a Null Pointer exception at runtime.
If I try to convert them to char, I'm told that a one character string can't be converted to char.

Those are only a small subset of the ways I've tried to test whether the input string is "A".

In any other language, this is the most trivial task one could ask it to do.

So, how is it done in Java?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2007
Added on Oct 17 2007
25 comments
315 views