views:

393

answers:

3

Hello, 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:

stack.push(valueOf(in));

Where 'in' is a char.

+3  A: 

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).

Carl Smotricz
Yes, that makes sense! Thank you.
Fred
@Carl - Character.valueOf is preferable since it caches and reuses previously created Character instances.
Stephen C
Yep, I know. Maybe I should take `new` out of my answer. But I really get a kick out of doing `new Boolean(val)`. < ZenMaster > There are as many truths as stars in the heavens! < /ZenMaster >
Carl Smotricz
+1  A: 

You are looking for:

stack.push(Character.valueOf(in));
rsp
+1  A: 

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

Andreas_D