我有一个 JTable
,它有两列和 10 行。当我从 JTable
读取第二列值时,我必须检查这些值是否是唯一值。
如何查看?
最佳答案
您可以使用Set以确定是否添加重复项。
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
}
}
关于java - 如何检查JTable中的值是唯一的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7525971/