DEV Community


Discussion on: The int vs. Integer pitfall of Java's ArrayList.remove()

djtai profile image
πŸ‡¬πŸ‡ΊπŸ‡²πŸ‡΅ David J. Taitingfong

Ahh, that is interesting. So...if it's not an int index then it's looking for a specific Object? This seems like a good Java interview question - pretty tricky IMO.

awwsmm profile image
Andrew (he/him) Author

Yep! Integer is a subclass of Object, so Java assumes you're looking for a specific Integer object in your ArrayList, even if the actual subclass is something totally different, like Character.