Originally posted by Sneha Kulkarni:
Can anybody please explain me about instanceof operator,how it is used etc?
"instanceof" operator is used to determine the object type at runtime.
You can take a decision based on the actual object so as to invoke its functionality.
A sample code would be:
Note: You can use only OBJECTS to check using instanceof operators as the term 'instance' indicates you can use the fully qualified classname in the checking as 'java.lang.String' instead of 'String'. This will be helpful to use the classes-happen-to-have-same-name (for example, java.awt.List and java.util.List) the instanceof operator returns true for the object when compared against any of its compatible and/or super class(es). Any object when compared against java.lang.Object would return true always Does that help you?
[ September 10, 2007: Message edited by: Raghavan Muthu ]