This question already has an answer here:
- How do I compare strings in Java? 23 answers
I am trying to check a Jlist for duplicates. If found, should delete repeated element. I printed values to console and output confirms that check1 and selectedRmv both have the value 'Motherboard' yet 'Hello' is never printed to console! This tells me if statement not executing. Wise advise anyone?
JButton rmvButton = new JButton("<<");
rmvButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//int index2 = list2.getSelectedIndex();
String selectedRmv = (String) list2.getSelectedValue();
DLM2.removeElement(selectedRmv);
//ListModel model = (list).getModel();
for(int i=0; i < DLM.getSize(); i++){
Object check1 = DLM.elementAt(i);
System.out.println("Check1= " + check1);
System.out.println("SelectedRmv= " + selectedRmv);
if (selectedRmv == check1){
DLM.removeElement(check1);
System.out.println("Hello");
}
}
DLM.addElement(selectedRmv);
}
});
Aucun commentaire:
Enregistrer un commentaire