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.

[2660 byte] By [djsperlinga] at [2007-11-26 21:57:33]
# 1
Pardon me if I don't understand your requirements correctly, but to avoid adding duplicates, wouldn't you have to compare the thing you might be adding to all the things already in the bag?
DrClapa at 2007-7-10 3:54:48 > top of Java-index,Java Essentials,New To Java...
# 2
You already have the code you need. If charAt(i) == input then return false else, return true. You method should iterate through an array and check each value, if exists then return false.
kikemellya at 2007-7-10 3:54:48 > top of Java-index,Java Essentials,New To Java...
# 3
GUESS WHAT HE DID http://forum.java.sun.com/thread.jspa?threadID=5149327&messageID=9558471#9558471
TuringPesta at 2007-7-10 3:54:48 > top of Java-index,Java Essentials,New To Java...
# 4
Whoa, take it easy pal. I had some computer problems staying connected to the internet. After I redid my loop around my code I reposted it. Didn't mean to be out of line. My fault.
djsperlinga at 2007-7-10 3:54:48 > top of Java-index,Java Essentials,New To Java...