java - Using an Integer ArrayList in Android -
i needing creating arraylist , adding integers them. essentially, have card game pulls card , saves id (bcid). want add pulled id arraylist, can avoid pulling same card twice. have setup below, keep getting duplicates. know cards pulling correctly, displays fine - repeated cards, unfortunately.
any can provide great! have done best include relevant parts. if need additional information, let me know.
public static integer bcid1, bcid2, bcid3, bcid4, bcid5, bcdcid; public static list<integer> usedcards = new arraylist<integer>();
in example below, supposed detect duplicate initialize sequence draw 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) { } }
use hashset instead of arraylist. set not allow duplicate.
Comments
Post a Comment