| 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
|
|
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
|
|
|
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
|
|
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);
[ June 13, 2007: Message edited by: Minh Tran ]
|
SCJP 1.4, SCWCD 1.4<br />email:mobject@gmail.com
|
 |
 |
|
|
subject: Arraylist 'contains' method
|
|
|