tags:

views:

511

answers:

1

Sorry, I'm a Java newb. I'm trying to figure out whether a number is a Double with something like this:

  if ( typeof ( items.elementAt(1) )== Double ) {
         sum.add( i, items.elementAt(1));
  }

Would appreciate if someone could tell me how to rearrange the syntax to make this work properly.

+16  A: 

Try this:

  if (items.elementAt(1) instanceof Double) {
     sum.add( i, items.elementAt(1));
  }
ski
+1. I'm also thinking you actually want to check `elementAt(0)`; majority of stuff in Java is zero-based.
ChssPly76