manaswi31 manaswi31 - 4 months ago 12
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 ?


Just loop through your list

for(Object object: objects){
    if(object instanceof A){
       // Do something wiht it