manaswi31 manaswi31 - 1 year ago 62
Java Question

Loop through List<object> to determine if particular object type exists java

In, I have a list getAorBorCorD as follows:

class Equip{
protected List<Object> getAorBorCorD;

class A{
class B{
class C{
class D{

In another module,

Equip equip = new Equip();

How can I check if getAorBorCorD contains Object type A ?

Answer Source

Just loop through your list

for(Object object: objects){
    if(object instanceof A){
       // Do something wiht it
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download