set - Searching in Hashcode doesn't work in Java -
i have
set tablica = new hashset();
and want search wrote this:
public void searchstudentbysurname() { int = tablica.size(); if (0 >= a) { joptionpane.showmessagedialog(null, "no data"); } else { string s = joptionpane.showinputdialog(null, "give me surname"); iterator itr = tablica.iterator(); while (itr.hasnext()) { string str = (string) itr.next(); if(tablica.equals(s)) { // if doesn't work (1) joptionpane.showmessagedialog(null, str); } } } }
}
i want know why (1) doesn't work.
you comparing string set, it's can't return true.
you meant compare str
- str.equals(s)
, not necessary. can replace entire while loop tablica.contains(s)
. that's set
s for.
Comments
Post a Comment