We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Instanceof keyword
Java Instanceof keyword
Sort by
recency
|
134 Discussions
|
Please Login in order to post a comment
import java.util.*;
class Student{} class Rockstar{ } class Hacker{}
public class InstanceOFTutorial{
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++; } String ret = Integer.toString(a)+" "+ Integer.toString(b)+" "+ Integer.toString(c); return ret; }
public static void main(String []args){ ArrayList mylist = new ArrayList(); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i
Math class services often include test preparation strategies and practice exams to help students prepare for quizzes, exams, and standardized tests TakeMyMathClassPro. This can help students feel more confident and perform better on assessments.
import java.util.*;
class Student{} class Rockstar{ } class Hacker{}
public class InstanceOFTutorial{
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++; } String ret = Integer.toString(a)+" "+ Integer.toString(b)+" "+ Integer.toString(c); return ret; }
public static void main(String []args){ ArrayList mylist = new ArrayList(); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i
// Comparing the class if(element.getClass() == Student.class) a++;
}