It is just checking the type of the object stored in the List, whether it is of type IdNamePair or IdValuePair...
According to that it does the typecasting, to call the appropriate method in those classes..
instanceof checks to see whether the reference on the left is of the type on the right. So list.get(i) instanceof IdNamePair checks to see if that entry in the List is actually an IdNamePair object.
If it is, your code casts it to an IdNamePair - so the instanceof is letting you check whether that cast is actually going to work. It looks as if you've got a List that contains objects of two different types*, so every time you get a value out you need to check which type it is.
* And I have to say, that's almost certainly not a good idea. That much casting is usually an indicator that there's a flaw in the design.