Javatpoint Logo

Enhance for Loop & different data type in the bracket of loop

By: koomar*** On: Sun Dec 18 18:33:21 IST 2016     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
private static List customers;
{
customers = new ArrayList();
customers.add(new Customer(101, "John"));
customers.add(new Customer(201, "Russ"));
customers.add(new Customer(301, "Kate"));
}

public Customer get(Long id) {

for (Customer c :customers) /*here "customers" and "c" both having different data type . Is it possible in this loop? */
{
if (c.getId().equals(id)) {
return c;
}
}
return null;
}



/*here "customers" and "c" both having different data type . Is it possible in this loop *?


If no. Then how to read List objects having different-different data type using enhance for loop?
Up0Down