wood burning stoves 2.0*
The moose likes Java in General and the fly likes Checking for a String in ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Checking for a String in ArrayList" Watch "Checking for a String in ArrayList" New topic
Author

Checking for a String in ArrayList

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
As I build the array list I want to make sure I don't add duplicate values. But the follwing code using contains always returns true.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I'm sorry, I don't see where that code returns anything at all. Could you explain the problem a bit more?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Steve Dyke wrote:As I build the array list I want to make sure I don't add duplicate values.

Why aren't you using a Set implementation then?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8



Also, if dConn.getManagerNameByDeptArrayList() always returns the same list, then this line of code seems a bit strange to me. List A is always going to contain element i of List A. Unless, that is, the elements of the list have a badly-implemented equals() method. But you implied they were String objects, so that can't be the case.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1393
Bear Bibeault wrote:
Steve Dyke wrote:As I build the array list I want to make sure I don't add duplicate values.

Why aren't you using a Set implementation then?


I am changing to LinkedHashSet

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking for a String in ArrayList
 
Similar Threads
I want to insert normal data and image in one servlet but am getting one problem ?
Is it possible to put a scriptlet inside the href attribute of a <a> tag?
Problem with ajax implementation using Jquery
passing parameter
Image insertion problem