开发者

problem with valueOf(), converting a char to Character in Java

开发者 https://www.devze.com 2022-12-11 07:41 出处:网络
I\'m trying to convert a char to Character before it gets pushed on a stack but get a \"cannot find symbol error\", I don\'t see what the problem might be. This is how I pass the char to the stack:

I'm trying to convert a char to Character before it gets pushed on a stack but get a "cannot find symbol error", I don't see what the problem might be. This is how I pass the char to the stack:

stac开发者_开发问答k.push(valueOf(in));

Where 'in' is a char.


valueOf is a class method of Character, among others. You can't just call it without a class to hang it off.

What you're really looking for is

Character.valueOf(in) or new Character(in).


You are looking for:

stack.push(Character.valueOf(in));


I hope, valueOf(char c) is defined in the same class where you have that call ... ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消