Hey DW. Working on a nice poker application and need some help. Right now I'm trying to go through two arraylists, one of chars and one of sorted ints (representing the suites, and numbers of the cards) and delete duplicating numbs (and the char/suite counterpart in the other array).

In this function, I have already made code that detects if a flush exists (and if it does, the char/suite is stored in soot). Here is the rest of the code:

for (int i =0; i < nubArr.size(); i++)
      {

     if (!nubArr.get(i+1).equals(null)) 
          {
              if (nubArr.get(i).equals(nubArr.get(i+1)))
              {
                  if (flush) //if theres a flush
                  {
                      if (cArr.get(i) != soot) //card doesnt match suite
                      {
                          cArr.remove(i); //found a dupe that doesnt match the flush suite
                          nubArr.remove(i); //so remove them both
                      }
                      else if (cArr.get(i+1) != soot)
                      {
                          cArr.remove(i+1);
                          nubArr.remove(i+1);
                      }
                  }
                  else //there isnt a flush.  so just erase the first card.
                  {
                        nubArr.remove(i);
                        cArr.remove(i);
                  }
              }
          }
      }

And here's my problem...
Notice the runtime error on line 4 where an element that doesnt exist in the AL is accessed to check to see if its null. This is where my problem is. I'm trying to check if I've reached the end of the array list. But I can't seem to find a good way of doing. I'm also trying to avoid iterators. Any help is appreciated.

Recommended Answers

All 2 Replies

As you already found out you can not check for something that is not there, something you did not declare.
You may consider simple work around like this if (i+1 != nubArr.size()) taking in consideration that i+1 can only be smaller than or equal to array list size, as for loop will not let you go over array list size

commented: Helped me with a problem. +1

thanks dude. appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.