Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6198729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:03:59+00:00 2026-05-24T04:03:59+00:00

Is there historical reasons to the two ambiguous List.remove ? List.remove(int) List.remove(Object) It seems

  • 0

Is there historical reasons to the two ambiguous List.remove?

  • List.remove(int)
  • List.remove(Object)

It seems like terrible design to me.
For a List<Integer> it just seems really confusing.

EDIT:

Everybody seems pretty fine with this. Let me precise things a bit.

Let’s say I have a List<Boolean>.

Integer idx = Integer.valueOf(2);
list.remove(idx)

Though idx is an object, Java compiles and will remove the item at index 2.

Now if it had been a List<Integer>, the very same code would have called a different method with a totally different behavior.

Let’s not talk about what would happen with Generics.

I feel like different behavior implies different names is a precious rule, especially within the same class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:04:01+00:00Added an answer on May 24, 2026 at 4:04 am

    First of all:

    • List.remove(int) removes an element at the specified index and
    • List.remove(Object) (or Collection.remove(Object)) removes the specified element.

    I’m not sure if this was already known, but for completeness sake, I thought I’d mention it.

    An important part to notice is that the API predates generics (and more importantly) auto-boxing by quite a bit (the collections API was introduced in Java 1.2 and auto-boxing was introduced in Java 5).

    So when they first designed the API, there was absolutely no way to confuse the two. Even if your List contained Integer objects, it’s simple: if you call the method with a primitive argument type (int), then it’s the index, if you pass in an Object (even if it’s Integer), then you pass in the object to remove.

    Granted, it’s still not the greatest idea (but quite a few Java APIs are … less than perfect), but the chance for confusion was much lower back then.

    The increased chance of confusion only exists since the int/Integer barrier became less visible thanks to auto-boxing and auto-unboxing.

    Sidenote: an important “feature” of the collections API is “short names for commonly used methods”. The previous “solution” of Vector/Enumeration had notoriously long names for pretty common operations:

    • Vector.elementAt() vs. List.get()
    • Vector.addElement() vs. Collection.add()
    • Enumeration.hasMoreElements()/nextElement() vs. Iterator.hasNext()/next()
    • Vector.removeElement() vs. Collection.remove()
    • Vector.removeElementAt() vs. List.remove(int)

    And the last one are where they probably went a bit too far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This just seems odd to me, most other things are lower case. Is there
My company has a large application written in VB6, and for historical reasons, the
I am having trouble accessing the attributes of a join in Rails3. There is
I have a class that uses INotifyPropertyChanged and have a List bound to a
Anyone any clue as to why there is an uppercase VOID macro defined in
In PHP, the string operator dot (.) is used to concatenate strings. For example:
IMPORTANT UPDATE This question was made over 9 years ago. It made sense then,
Some code I am inheriting uses Python's psycopg2 module to return mxDateTime objects from
I'm written my first unit-test and I think it is too dependent on other
Before starting, I do have a very particular question and if you want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.