2

I'm trying to get the last added item in an ArrayList to compare it to the next item I'm about to add to it. If they are equal, continue. Like:

if (stringArray.get(stringArray.IndexOfLastItemAdded()) == compareLastItemToThis) {
    continue;
}
else {
    stringArray.add(compareLastItemToThis);
}

I know IndexOfLastItemAdded doesn't exist, but is there something similar to it?

Grux
  • 584
  • 1
  • 11
  • 20
  • Also note that you can not compare strings using the `==` operator. Rather, use `equals( compareListItemToThis )`. – 323go Apr 10 '14 at 02:09

1 Answers1

9
stringArray.get(stringArray.size() - 1) ;

shoudl give u the last item in stringArray list

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136