You are viewing a single comment's thread. Return to all comments →
//** using java 7 static String count(ArrayList mylist){ int a = 0,b = 0,c = 0; for(int i = 0; i < mylist.size(); i++){ Object element=mylist.get(i); if(element instanceof Student) a++; if(element instanceof Rockstar) b++; if(element instanceof Hacker) c++; }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Instanceof keyword
You are viewing a single comment's thread. Return to all comments →
//** using java 7 static String count(ArrayList mylist){ int a = 0,b = 0,c = 0; for(int i = 0; i < mylist.size(); i++){ Object element=mylist.get(i); if(element instanceof Student) a++; if(element instanceof Rockstar) b++; if(element instanceof Hacker) c++; }