comparison - Comparing Stack value to String in java -
i trying following code:
import java.util.stack; public class helloworld{ public static void main(string []args){ stack s=new stack(); s.push(5-4); s.push(9); s.push(51); if(s.get(1).equals("9")) system.out.println("yes comparable"); system.out.println(s.get(1)); } } the actual output is:
9 i expect output be:
yes comparable 9 i unable figure out. have tried s.get(1)=="9" doesn't work too. might key behind this? both not strings? or 1 string 1 object still comparable. can enlighten me on this?
9 integer. "9" string.
s.get(1).equals("9"); // false s.get(1).equals(9); // true
Comments
Post a Comment