I want to see if a character in my string equals a certain other char value but I do not know what the char in the string is so I have used this:
if ( fieldNames.charAt(4) == "f" )
"Operator '==' cannot be applied to 'char', 'jav.lang.String'"
"g" == "h"
if ( fieldNames.charAt(4) == 'f' )
"f" is a
fieldNames.charAt(4) is a
char. you should use
'f' for check char
"g" == "h" works because both g and h are
and you shouldn't use
"g" == "h" you should use
"g".equals("h") instead .
you can use == for
primitive data types like
char,int,boolean....etc.but for the
objects like String it's really different.
To know why read this
but you can use also
'g' == 'h'
you should wrap Strings by double quotation and char by single quotation
String s="g"; char c='g';
but char can only have one character but String can have more than one
String s="gg"; valid char c='gg'; not valid