J
justineee
Hi Everyone,
I am making a project that runs like a word storage. The user inputs
words and stores it in arrays. Also, the user can delete words and
display the new collection of words. However, I am having problems in
deleting an element in an array.
Here is my code.
if (jnd.getSource()==deleteButton && (!(inputDelete.equals(""))))
{
getInputDelete = inputDelete.getText();
int dCtr;
List<String> arrayWordsCopy = Arrays.asList(arrayWords);
for (dCtr = 0; dCtr < arrayWords.length; dCtr++)
{
if (getInputDelete.equalsIgnoreCase(arrayWords[dCtr]))
{
arrayWordsCopy.remove(dCtr);
textArea.append("The word "+getInputDelete+" has been deleted in
the dictionary.");
}
else
{
}
}
arrayWordsCopy.toArray(arrayWords);
}
I tried to convert the array to List temporarily so I can use the
".remove" method. Then I will get it back to an array so the element
will be deleted permanently. There is no error in this code when I
compile it but when I run the program and I press the button
"deleteButton", there is a run-time error the occurs.
Can anyone please help me to delete an element in an array?
I am making a project that runs like a word storage. The user inputs
words and stores it in arrays. Also, the user can delete words and
display the new collection of words. However, I am having problems in
deleting an element in an array.
Here is my code.
if (jnd.getSource()==deleteButton && (!(inputDelete.equals(""))))
{
getInputDelete = inputDelete.getText();
int dCtr;
List<String> arrayWordsCopy = Arrays.asList(arrayWords);
for (dCtr = 0; dCtr < arrayWords.length; dCtr++)
{
if (getInputDelete.equalsIgnoreCase(arrayWords[dCtr]))
{
arrayWordsCopy.remove(dCtr);
textArea.append("The word "+getInputDelete+" has been deleted in
the dictionary.");
}
else
{
}
}
arrayWordsCopy.toArray(arrayWords);
}
I tried to convert the array to List temporarily so I can use the
".remove" method. Then I will get it back to an array so the element
will be deleted permanently. There is no error in this code when I
compile it but when I run the program and I press the button
"deleteButton", there is a run-time error the occurs.
Can anyone please help me to delete an element in an array?