java - Get index of objects in an array -


i trying find index of each object in array.

   public class monstertest {      public static void main(string[] args) {         // todo auto-generated method stub         monster [] ma = new monster[3];         ma[0] = new vampire();         ma[1] = new dragon();         ma[2] = new monster();         for(int x = 0; x < 3; x++) {             system.out.println(ma[x].getclass());             system.out.println(java.util.arrays.aslist(ma[x]).indexof(x));             ma[x].frighten(x);          }      }  } 

am using java.util.arrays.aslist(array).indexof(element) method here correct? (well not because output incorrect.

you have - it's x. don't need use such specific functions have.

public class monstertest {      public static void main(string[] args) {         // todo auto-generated method stub         monster [] ma = new monster[3];         ma[0] = new vampire();         ma[1] = new dragon();         ma[2] = new monster();         for(int x = 0; x < 3; x++) {             system.out.println(ma[x].getclass());             system.out.println(x);             ma[x].frighten(x);          }      }  } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -