String/char operators

Is there an equivalent to the "!" operator for strings and characters, to put it in context, how would I write the piece of code between the parenthesis correctly?

while("Y" != answer)

{

number=1;

}

[339 byte] By [datawerda] at [2007-11-26 20:02:08]
# 1

For strings

while(!"Y".equals(answer))

for char (primitives)

while('Y' != answer)

The equals method compares the contents of the given Strings. The != compares their references

Message was edited by:

Ruly-o_O

Ruly-o_Oa at 2007-7-9 23:01:06 > top of Java-index,Java Essentials,New To Java...
# 2

You can write

while(!"Y".equals(answer) { //"Y" does not equal "answer"

//code here

}

Of course, answer has to be of type string.

You can also do the same with chars. Same code.

*edit*

Link for char. I assume it compares the value's of the chars and determines if they are equal from there:

http://java.sun.com/j2se/1.3/docs/api/java/lang/Character.html#equals(java.lang.Object)

Message was edited by:

lethalwire

lethalwirea at 2007-7-9 23:01:07 > top of Java-index,Java Essentials,New To Java...