JYnet
asked on
Character and char
just wondering how to compare(convert) the Character datatype to char datatype?
i store Character inside a Stack and want to compare the content of the Stack with char.
how this can be done?
i store Character inside a Stack and want to compare the content of the Stack with char.
how this can be done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//where stack is your Stack object
myChar char = "a";
for (int i = 0; i < stack.size(); i++){
if (((Character)stack.element At(i)).cha rValue()== 'a'){
System.out.println("Charac ter " + i + " in the stack is equal to " + myChar);
}
}
myChar char = "a";
for (int i = 0; i < stack.size(); i++){
if (((Character)stack.element
System.out.println("Charac
}
}
Damn, sorry...that should have been :
for (int i = 0; i < stack.size(); i++){
if (((Character)stack.element At(i)).cha rValue()== myChar){
System.out.println("Charac ter " + i + " in the stack is equal to " + myChar);
}
}
Basically you iterate through the Stack getting each object and casting it to a Character (since all items in a Stack are upcast to Object) and then comapring it to a char.
for (int i = 0; i < stack.size(); i++){
if (((Character)stack.element
System.out.println("Charac
}
}
Basically you iterate through the Stack getting each object and casting it to a Character (since all items in a Stack are upcast to Object) and then comapring it to a char.
if (chObj.charValue() == 'a') System.out.println("equal"