Sheph, on 14 February 2012 - 02:08 PM, said:
public class ProductList extends ArrayList<Product> {
public boolean codeExist(int code) {
for(Product p : this) {
if(p.getCode() == code)
return true;
}
return false;
}
}
Then you can create a new ProductList() wherever you need it, and call productList.codeExists(code) wherever you want to check that a code already exists in the list.I didn't want to create new class altogether, i wanted to include the methods in my Item class along with the setter/ getter methods. I'm a beginner, i think i'll put the methods in main.
What i'm don't quite understand is
boolean codeExist(int code, [b]List<Product> prods)[/b] {
for(Product p: prods) {
if(p.getCode() == code)
return true;
}
return false;
Are we creating a new list prods specifically to test codes?

New Topic/Question
Reply




MultiQuote


|