CONTAINS METHOD IN ARRAYLIST PROBLEM.
- From: justineee <aguas.justine@xxxxxxxxx>
- Date: Mon, 10 Nov 2008 09:01:57 -0800 (PST)
if (!(dictionary.contains(getInputAdd)))
{
if (!(getInputAdd.equals("")))
{
word = new Word (getInputAdd);
dictionary.add(word);
inputAdd.setText("");
aCtr++;
if (aCtr==(inputConfigQty))
{
addButton.setEnabled(false);
inputFind.setEditable(true);
inputDelete.setEditable(true);
resetButton.setEnabled(true);
displayButton.setEnabled(true);
sortButton.setEnabled(true);
findButton.setEnabled(true);
deleteButton.setEnabled(true);
clearButton.setEnabled(true);
sortButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayButton.setEnabled(true);
sortDecButton.setEnabled(true);
displayAllButton.setEnabled(true);
addDefButton.setEnabled(true);
delDefButton.setEnabled(true);
addDefOk.setEnabled(true);
delDefOk.setEnabled(true);
}
}
else
mBox.setText("Please put\na word.");
}
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
}
My program lets the user add words to store it like a customized
dictionary. However, he/she can't add the same words so I used the
contains method (dictionary is an ArrayList of a class I create Word,
ArrayList<Word>) to check if the dictionary already have the word. But
when I try it, the program still lets me add the same word so it
doubles up.
When I add 'a', it is in the dictionary. Then when I add 'a' again,
it's supposed to do this:
else if (dictionary.contains(getInputAdd))
mBox.setText(getInputAdd+" is already\nin the
dictionary.");
It doesn't work for me, it will still add 'a' many times. By the way,
getInputAdd is a String.
Help please. Thanks.
.
- Follow-Ups:
- Re: CONTAINS METHOD IN ARRAYLIST PROBLEM.
- From: Brian Odsgaard
- Re: CONTAINS METHOD IN ARRAYLIST PROBLEM.
- From: Lew
- Re: CONTAINS METHOD IN ARRAYLIST PROBLEM.
- Prev by Date: Re: Possible bug in Calendar
- Next by Date: Re: Web User Interface Techniques
- Previous by thread: OVERNITE ACM ICPC 2009 MULTI PROVINCIAL PROGRAMMING CONTEST
- Next by thread: Re: CONTAINS METHOD IN ARRAYLIST PROBLEM.
- Index(es):