This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Arraylist 'contains' method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Arraylist Watch "Arraylist New topic
Author

Arraylist 'contains' method

Ranadhir Nag
Ranch Hand

Joined: Mar 09, 2006
Posts: 138
I have an ArrayList which is filled in with multiple Strings.
However,when I use the 'contains' method to search if a given string exists in the arraylist,I do not get the desired result.
Why is it so - i thought the 'contains' method uses 'equals' to compare by value.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12271
    
    1
Looking at the source code for ArrayList, I see that it does indeed use equals(). Therefore the reason you dont get the expected result must reside in your code.

What are you expecting and what are you getting?

Bill


Java Resources at www.wbrogden.com
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Show us some code; maybe we can tell you what's going on.


[Jess in Action][AskingGoodQuestions]
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 852
Does anyone know the best place to look for the code that makes up the jdk? Is this for ArrayList for example? https://openjdk.dev.java.net/source/browse/openjdk/jdk/trunk/j2se/src/share/classes/java/util/


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

Does anyone know the best place to look for the code that makes up the jdk?

A source archive is bundled with your jdk. Check your JAVA_HOME for a file called src.zip.


[My Blog]
All roads lead to JavaRanch
Minh Tran
Greenhorn

Joined: Jun 03, 2007
Posts: 19
In contains(Object obj);

o==null ? e==null : o.equals(e) from java.util.AbstractCollection

[ June 13, 2007: Message edited by: Minh Tran ]

SCJP 1.4, SCWCD 1.4<br />email:mobject@gmail.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arraylist 'contains' method
 
Similar Threads
Object that contain ArrayList
How to crate Multiple ArrayList from one ArrayList
problem in arraylist
issue with stack
how ro compare two arraylist objects