Re: converting String type to char
From: David Heath (barcodedave_at_netscape.net)
Date: 02/22/04
- Next message: Matt Parker: "Re: Java program MVC"
- Previous message: Paul Thompson: "Changing Directories"
- In reply to:(deleted message) Mark Haase: "Re: converting String type to char"
- Next in thread: Lāʻie Techie: "Re: converting String type to char"
- Reply: Lāʻie Techie: "Re: converting String type to char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 22 Feb 2004 00:24:51 GMT
Hi Mark,
Gender is a String type. The original post was because I was going to
try changing the attribute to a char type. After seeing some of the
responses I saw that it wasn't necessary. if(gender.equals("M") worked.
This all started because the compiler didn't throw an error on the line
if(gender == "M")
but the code didn't work. I now understand that == is used to compare
integer or char types.
David
Mark Haase wrote:
> In article <uQvZb.25468$Xp.103864@attbi_s54>,
> David Heath <barcodedave@netscape.net> wrote:
>
>
>>Steve,
>>
>>What I'm trying to achieve is to display "Welcome Mr./Ms. <name>" based
>>on user input to name and gender. This is the code
>>
>> public void welcome()
>> {
>> if(gender == "M") {
>
>
>
> Does it even compile? I should think not. You should have posted the
> error message, but I can explain part of the problem right now.
>
> When you put double quotes around something, that declares it as a
> String literal. So you're comparing a char to a String, which is illegal.
>
> Put single quotes around a char to tell the compiler that its a char
> literal.
>
- Next message: Matt Parker: "Re: Java program MVC"
- Previous message: Paul Thompson: "Changing Directories"
- In reply to:(deleted message) Mark Haase: "Re: converting String type to char"
- Next in thread: Lāʻie Techie: "Re: converting String type to char"
- Reply: Lāʻie Techie: "Re: converting String type to char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|