Hi, I would like to know how I can use the instanceof operator to test if a reference is an instance of some array. I tried the following code, but it generates compiler error. String[] sa = { "This", "is", "a", "test" }; System.out.println(sa instanceOf String[]); Thanks for your help. Vani
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Originally posted by Vani, Kadur: Hi, I would like to know how I can use the instanceof operator to test if a reference is an instance of some array. I tried the following code, but it generates compiler error. String[] sa = { "This", "is", "a", "test" }; System.out.println(sa instanceOf String[]); Please remember "instanceof" is correct NOT "instanceOf" (No capital "O" please!) Jaypii Thanks for your help. Vani
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Please remember "instanceof" is correct NOT "instanceOf" (No capital "O" please!) Jaypii
check your uppercase/lowercase it's instanceof not instanceOf. But you cans use it to check for arrays just fine: try this: class Instance { public static void main(String[] args) { int [] i = {0,1,2,3,4,5};; double [] d = {0.0, 1.0, 2.0, 3.0, 4.0}; String [] sa = {"This", "is", "a", "test"};