I'm working on some Java code, and I create a string with characters of another string.
example: strStringName = "" + strAnotherString.charAt( 0 ) + strAnotherString.charAt( 1 );
Since I include the empty quotes at the beginning, this assignment statement should automatically typecast the added characters as string type. This statement works fine for me in my code; this is not where the problem lies.
Next, I evaluate whether that string is equivalent to a string literal in an IF statement.
example:
if (strStringName == "ab")
{
(this doesn't work, blah blah blah)
}
For some reason, this IF statement evaluates the express as "false"...which it shouldn't do!
However, if I use the charAt method, it works...but it sure is a lot of added code I have to write which I shouldn't have to.
example:
if (strStringName.charAt(0) == 'a' && strStringName.charAt(1) == 'b')
{
(this works, blah blah blah)
}
wtf is going on??!!!!...is it a bug with the SDK/JDK?...bleh!
2006-11-19
07:47:21
·
1 answers
·
asked by
entranced82
3
in
Programming & Design