Char cannot be dereferenced equalsignorecase

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.

Forum: Beginning Java. Jem Edwards. The last piece of my puzzle - I don't understand how to use the equalsIgnoreCase method. In my program I ask the user to input a 'c' or 'f' for celcius or farenheit. I want my program to ignore the case and accept either upper or lowercase.

I have searched the internet for the past two days and every site I found including Java Sun Tutorial and Java Ranch doesn't break it down clearly to me.

Haven't heard a peep from my homework board since I posted early this morning so I'm back here for help.

Comparing Strings using equals() & equalsIgnoreCase() in Java (HINDI)

David Weitzman. Your declaration of fahrenheitCelsius probably looks something like this: char fahrenheitCelsius; Note that fahrenheitCelsius is not a java.

String -- it's a char. Michael Morris. Hi Jem, Apparently your variable fahrenheitCelsius is declared as a char. Since a char is a primative, the compiler is telling you that it cannot be dereferened. The equalsIgnoreCase is a member of the String class.

So, if you want to use that method you'll need a String. Thank you David and Michael. You were both exactly right about the declaration of fahrenheitCelsius. I tried both solutions and both gave me a couple of compiling errors. So after working on errors for both programs I was able to get the program with David's solution to compile however now I can't get it to give me an output.

Previously I was able to get the program to do the conversions as long as I entered an uppercase C or F but now when I enter any case it gives me the System. I've narrowed down my errors using Michael's solution and I'll try to fix those also so I can compile and see if it runs. I figure still trying to fix the errors will help me learn more about Java. Would someone please give me an opinion on why my program no longer gives me the answer? Thank you!

I was expecting that you might come across this. But it's good for you to know anyway. You're not using equalsIgnoreCase. Not so. First read Cup Size -- a story about variables. That's was a long-winded way of saying you need to replace fahrenheitCelsius! Actually you should probably follow Michael's suggestion and look at the Character class. Applying Character. Chris Mathews.

char cannot be dereferenced equalsignorecase

Your other option is to read in an actual String from the console.This program is supposed to calculate the balance of a checking account after the user has entered the type of action withdrawl, deposit they would like to do. My output should be a report that prints the beginning balance, the action deposit or withdrawlthe amount and the ending balance.

Since amount and balance are same type double the system. Thank you guys so far for your input. I did the suggested changes and I am getting 2 error messages, : char cannot be dereferenced if accttype.

The program is supposed to ask the user for the checking account balance, amount to witdrawl or deposit and when the user finally hits "B" for balance then it is supposed to give an output of the transaction, amount and balance. Ok i have gotten stuck on this program and I need help This program is supposed to calculate the balance of a checking account after the user has entered the type of action withdrawl, deposit they would like to do.

char cannot be dereferenced equalsignorecase

Thank You Guys In Advance. Edited 7 Years Ago by Dani : Formatting fixed. Edited 7 Years Ago by TrustyTony : fixed formating. Is there anyone willing to help me more?? Getting Started: Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and adhere to our posting rules. Edit Preview.

H1 H2. Post Reply.

char cannot be dereferenced equalsignorecase

Insert Code Block. Share Post. Permanent Link. Promote Question. Would you like to see this question answered quickly?But abc is a const string Its stored in initialized data segment.

The pointer is to be known by the name "p," and can point to any char or contiguous array of chars anywhere. Hence in this declaration, a can be made to point to a different string whereas in the first declaration,a cannot be assigned to another string directly.

It can be done only through strcpy CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying. Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want.

Java String equalsIgnoreCase()

All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience. More Questions from This Interview.

char cannot be dereferenced equalsignorecase

Comment hidden because of low score. Click to expand. I agree with gomchal - desi February 26, Flag Reply. Dear friends remember sizeof works only at compile time. Both are stored in stack. Add a Comment Add a Comment. Writing Code? Add Question. CareerCup is the world's biggest and best source for software engineering interview preparation.

See all our resources. Open Chat in New Window. What's Going On. Report a Bug or Issue. Books is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Assine o RSS

Learn More. Videos CareerCup's interview videos give you a real-life look at technical interviews. Resume Review Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. Mock Interviews Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want.We have seen earlier comparing two Character objects with equals method. It was case sensitive comparison.

Infact, Character class does not have a method like equalsIgnoreCase. But String has one. Apply a small technique to do case insensitive comparison with characters. Just convert both the characters in comparison either to uppercase or lowercase. For this use toUppertCase or toLowerCase methods and then compare.

Output screenshot of Use equalsIgnoreCase with Character objects. Pass your comments and suggestions to improve the quality of this tutorial "Use equalsIgnoreCase with Character objects". Here equals method of String class is used to compare two characters. Or you can use equalsIgnoreCase method for case-insensitive comparison. The above program is a mater of interest and not used practically as equals you can use directly with character objects.

See equals example in the same series. Your email address will not be published. Save my name, email, and website in this browser for the next time I comment. Notify me of follow-up comments by email. Notify me of new posts by email. Leave a Reply Cancel reply Your email address will not be published.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time.

Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. What I want is no matter what the user inputs, if the first letter of their input is either a 'y' or 'n' regardless of case, it will print "game start".

I've tried equalsIgnoreCase with the "letter" variable but it gives the error: char cannot be dereferenced. Any recommendations will be really appreciated on this! For your case, if you want to use that method, you can do this:.

Learn more. Java - charAtequalsIgnoreCase, if statement testing? Ask Question. Asked 5 years, 2 months ago. Active 5 years, 2 months ago. Viewed 4k times. Krease ClaytonR ClaytonR 43 1 1 silver badge 5 5 bronze badges.

Use equalsIgnoreCase() with Character objects

Is that supposed to be a 'p' or a 'n'? Your code checks for y and p. Active Oldest Votes. Try use Character toLowercase : if Character. M Anouti M Anouti You could pre-build a set of acceptable characters. OldCurmudgeon OldCurmudgeon 58k 15 15 gold badges 98 98 silver badges bronze badges.

Holger - Working on that If you want to test against a pre-built a set of acceptable characters, you may consider "yYnN". For such a small set, hashing is not faster than a linear search. Holger - I was thinking of using a custom comparator too - but decided that was a little too OTT.

Good point on the indexOf.Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people.

Registration is quick and best of all free. We look forward to meeting you. Members have full access to the forums. Advertisements are removed for registered users. Remember Me? Advanced Search. Please help. Results 1 to 6 of 6.

Java error: char cannot be dereferenced

Thread: Char cannot be dereferenced!! Char cannot be dereferenced!! Hi all im working on a program and have got the error "char cannot be dereferenced". The for loop iterates through the array "people" and sends a message to each one using the method "getPerson ".

This method gets a single character from a StringBuilder array. The method is declared as the return type char so i used.

I am a novice in java so im not even sure im going about this theright way! I hope someone can help because I just cant see a way forward! Thankyou in advance for anyone willing to help.

Last edited by helloworld; February 13th, at PM. Related threads: Char cannot be dereferenced Check Password Program Rock Paper Scissors issue decimal to hexadecimal 2d 4x4 array insdie a 1d array.Java has two different types of variables: primitive and objects and only objects are reference types.

The type int is a primitive and not an object. Dereferencing is the process of accessing the value referred to by a reference.

Since, int is already a value not a referenceit can not be dereferenced. Primitives byte, char, short, int, long, float, double, boolean are not objects and do not have member variables or methods. They're just simple values. So you cannot do somePrimitive. So in the above example, x is an int, a primitive, and therefore cannot be dereferenced - meaning x. This means that there are primitive typesoriginally designed for speed, that do not behave as objects.

The primitive types exist either as local variables on the stack, or as fields static or not of objects. In Java, objects are always allocated on the heap : if you have a local variable that seems an object, then the object itself is allocated on the heap and the stack contains only a reference, i.

Important to note that NOT to stack memory. As a result of this fact, you cannot dereference a primitive type because you cannot create a reference to something different than an object, primitive types are not objects.

So, we can say that accessing the state or behaviour of an object using its reference with the help of the dot. Home C VB. Int cannot be dereferenced: Java Java has two different types of variables: primitive and objects and only objects are reference types.

Java Dereferencing Java has two different types of variables: primitive and objects and only objects are reference types. Reached end of file while parsing Unreachable statement error in Java How to fix java. SocketException: Connection reset. All other trademarks are property of their respective owners.