Reputation: 1724
I have a JComboBox call cmb_user_id
, I get all the user ID from database and save it inside an array of objects called borrow_data
, but there is some duplicated data in it, so I use .contains()
method to filter it, below is my code:
ArrayList<String> al_id = new ArrayList<>();
cmb_user_id.addItem("Select One");
for(int i = 0; i < borrow_data.length; ++i)
{
if(!al_id.contains(borrow_data[i].getUser().getId()));
{
cmb_user_id.addItem(borrow_data[i].getUser().getId());
al_id.add(borrow_data[i].getUser().getId());
System.out.println("Content: " + borrow_data[i].getUser().getId());
}
}
But after all, all data are still saved into cmb_user_id
, including the duplicated data, my filter doesn't work at all.
Upvotes: 0
Views: 91
Reputation: 33875
if(!al_id.contains(borrow_data[i].getUser().getId()));
Has a ;
at the of it, meaning that the following {...}
will always execute.
Upvotes: 4