大家帮我看下这是一段代码 有俩个set里面放的是查询出来的值现在要进行比对 如果有值set,remove(值)但是入库了还是元数据库7各值似乎set.remove()不好使, 但是还有一点插入的全是相同的值7个1561164222 郁闷呀这是我的代码
public void addMap() {
Object[] sp=set.toArray();
for(int a=0;a<sp.length; a++){
System.out.println(sp.length+"yuanshitable");
Object[] sb=se.toArray();
for(int i=0;i<sb.length; i++){
System.out.println(sb.length+"black----table");
if(sp[i].equals(sb[i])){
set.remove(sp[i]);
System.out.println(sp[i]+"----------");
}
else{
try{
pst=con.prepareStatement("insert into lv_black_phone(blackphone) values(?)");
pst.setString(1,(String)sp[i]);
pst.executeUpdate();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
pst.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}
}
求大家 帮看看谢谢了
public void addMap() {
Object[] sp=set.toArray();
for(int a=0;a<sp.length; a++){
System.out.println(sp.length+"yuanshitable");
Object[] sb=se.toArray();
for(int i=0;i<sb.length; i++){
System.out.println(sb.length+"black----table");
if(sp[i].equals(sb[i])){
set.remove(sp[i]);
System.out.println(sp[i]+"----------");
}
else{
try{
pst=con.prepareStatement("insert into lv_black_phone(blackphone) values(?)");
pst.setString(1,(String)sp[i]);
pst.executeUpdate();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
pst.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
}
}
求大家 帮看看谢谢了
要这么用Iterator iter= set.iterator();
iter.remove();