I am needing help creating an ArrayList and adding some Integers to them. Essentially, I have a card game that pulls the card and then saves the ID (BCID). I want to add this pulled ID to an ArrayList, so I can avoid pulling the same card twice. I have it setup as below, but I keep getting duplicates. I know the cards are pulling correctly, as it displays everything fine - just repeated cards, unfortunately.
Any help you can provide would be great! I have done my best just to include the relevant parts. If you need additional information, let me know.
public static Integer bcid1, bcid2, bcid3, bcid4, bcid5, bcdcid;
public static List<Integer> usedCards = new ArrayList<Integer>();
In the example below, it is supposed to detect the duplicate then initialize the sequence to draw a different card.
public static void setIDs()
{
try
{
bcid1 = Integer.parseInt(bc1);
usedCards.add(bcid1);
}
catch(NumberFormatException nfe)
{ }
try
{
bcid2 = Integer.parseInt(bc2);
if (usedCards.contains(bcid2))
{
try
{
blueCard2(ctx);
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
usedCards.add(bcid2);
}
}
catch(NumberFormatException nfe)
{ }
try
{
bcid3 = Integer.parseInt(bc3);
if (usedCards.contains(bcid3))
{
try
{
blueCard3(ctx);
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
usedCards.add(bcid3);
}
}
catch(NumberFormatException nfe)
{ }
try
{
bcid4 = Integer.parseInt(bc4);
if (usedCards.contains(bcid4))
{
try
{
blueCard4(ctx);
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
usedCards.add(bcid4);
}
}
catch(NumberFormatException nfe)
{ }
try
{
bcid5 = Integer.parseInt(bc5);
if (usedCards.contains(bcid5))
{
try
{
blueCard5(ctx);
} catch (IOException e) {
e.printStackTrace();
}
}
else
{
usedCards.add(bcid5);
}
}
catch(NumberFormatException nfe)
{ }
}
bc1,bc2, etc. come from?