Tell me more ×  I have an ObjectInputStream which needs to read
two different inputs which are a String and my own created
object. I have a thread which constantly waits for an input and
depending on the input be it a string or object it will process
the result. I need a way for the input to be able to distinguish
between the two.  Any help would be great.   share|improve this
question Can you give more details about your problem? A sample
code would be better. –  ovunccetin Apr 10 '11 at 11:53 add
comment  2 Answers  up vote 3 down vote accepted  Isn't it a
case of doing:  if (objectFromStream instanceof YourObejct) {
YourObject obj = (YourObject) objectFromStream;  } else if
(objectFromStream instanceof String) {      String str =
(String) objectFromStream;  } else {   // throw excepption..
share|improve this answer add comment  If the only two choices
are Sting and your object then you can try this:      Object obj
= ois.readObject();     if(obj instanceof String){        String
s = (String)obj;