This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Why contains() method takes Object, even if I have parameterized my ArrayList with String. Only String can be added and we need not to cast what get(...) method returns, but why contains() ,indexOf(),remove() ask for Object.
indexOf() also requires Object remove() also requires Object (another remove() asks for index though)
You are right. We will never be able to add anything other than string in to this list. But the same is not ture for the contains method.It can check for any thing other than the string.As you see the following prints false.
I know that you are going to ask me the question
"If it not taking in any thing other than string, why is it checking for some thing else?"