Hashing with jTable
hi,
I am doing a media player project and I have got stuck when trying to code for the option "Remove Duplicate Entries". I am using jTable, and I have written the code to add it to the hash, but I dont know how to get it back... My code is as following..
privatevoid RemdupentriesActionPerformed(java.awt.event.ActionEvent evt){
int rcnt = jTable1.getRowCount();
HashSet hash =new HashSet();
for(int i = 0; i < rcnt; i++){
hash.add(jTable1.getValueAt(i,1));
}
}
can anyone pls help me out of this. In the above code, i represents the row value and 1 is the second column, where I store the absolute path of the song that is been played...
Message was edited by:
Spanian
[1054 byte] By [
Spaniana] at [2007-11-26 22:31:34]

ok, first, this isn't "hashing", it's dealing with Sets</peeve> :-)
Sets aren't really designed for you to get a particular element out of on its own. you can iterate over the Set getting them all out, but they're not in any particular order. if you need to get at a particular element, you're better off using a List such as ArrayList, or a Map such as HashMap
thank u for the support..,
I have completed it...
my code is as follows..
private void RemdupentriesActionPerformed(java.awt.event.ActionEvent evt) {
int rcnt = jTable1.getRowCount();
LinkedHashSet<String> hash = new LinkedHashSet<String>();
for(int i = 0; i < rcnt; i++){
hash.add((String)jTable1.getValueAt(i,1));
}
for(int i = 0; i < rcnt; i++)
((DefaultTableModel)jTable1.getModel()).removeRow(0);
for(String cur : hash) {
String name = cur.substring(cur.lastIndexOf(File.separatorChar));
((DefaultTableModel)jTable1.getModel()).addRow(new String [] {name, cur, "", ""});
}
}