Reputation: 2757
I have a JTable
which has two columns and 10 rows. When I read second column values from the JTable
, I have to check whether those are unique values.
How to check?
Upvotes: 1
Views: 2310
Reputation: 1753
You could use a Set to determine if duplicates are being added.
TreeSet set = new TreeSet();
TableModel tableModel = table.getModel() ;
for(int i=0; i<tableModel.getRowCount();i++){
Object obj = tableModel.getValueAt(i, 2);
if(!set.add(obj)){
//throw duplicate error
}
}
Upvotes: 8