aspose file tools*
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
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: 1466
    
    1
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: 18649
    
    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: 61413
    
  67

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: 18649
    
    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: 1466
    
    1
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