adding duplicate values into a bag
Hello, I've been working on this project where I have to add characters from and input string into a bag. I have the program and the bag collection working properly. I'm trying to adjust the add() method so it will only insert a character into the collection if no duplicate values exist, and return true. If there is a duplicate value, it should return false.
Here is my snippit of code for adding characters to "NodupBagA":
// add characters from the string to NodupBagA
do{
for (i = 0; i < str.length(); i++)
{
for(j=0; j < strTest.length(); j++)
{
if (strTest.charAt(j) == str.charAt(i))
NodupBagA.add(str.charAt(i));
j++;
}
}
}while (i < str.length());
Here's my code for the add method from the NodupBag Class
/**
* Inserts item in the NodupBag if space is available; that is,
* it the size is less than the capacity.
* Returns <tt>true</tt> if a new element is added and <tt>false</tt>
* if a duplicate value exists.
*
* @param item element that is added if space is available..
* @return <tt>true</tt> if a new element is inserted in the NodupBag.
*
*/
publicboolean add(T item)
{
boolean returnValue;
if (NodupBagSize >= NodupBagArr.length)
returnfalse;
else
{
// append item at index bagSize only if
// no duplicates exist
NodupBagArr[NodupBagSize] = item;
// increment bagSize and return true
NodupBagSize++;
returntrue;
}
}
I'm really having a lot of trouble getting this to not accept duplicate values. could someone please help. its tormenting me.

