This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I've got String bar = "SDRTRed"; //well, not really, it's one of a number of different strings like this being passed in char foo = bar.charAt(3); Then I want to say if (foo == 'R') { System.out.println("I found Reading"); } But it the compiler keeps telling me: operator == cannot be applied to char, java.lang.String Ok, I can figure out what that means :-) So I tried if (foo.equals('R')), but it says I can't do that either. So, if you search in the java doc stuff for char and equals, you get more hits then you can shake a stick at. Do I really need to use the substring() method of the String to determine if it .equals() what I'm looking for? Thanks Lara
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Welcome to JavaRanch Lara. Umm, I don't see anything wrong with the code. I just compiled and ran this:
And it works fine. Are you sure that you are using single quotes in the if statement?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Lara Fabans
Greenhorn
Joined: Jun 11, 2003
Posts: 2
posted
0
>> Welcome to JavaRanch Lara. Thanks! I hope I can give something in return soon. >> Umm, I don't see anything wrong with the code. I just compiled and ran this: Darn :-) >> And it works fine. Are you sure that you are using single quotes in the if statement Yuppers: char testSub = testId.charAt(2); if (testSub == 'R') {
It's webObjects 5.2 using jdk1.3.1 If it's *supposed* to work that way, I'll try again. Maybe I've got a secret handshake character in there somewhere. Thanks