This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 1391
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: 18121
    
    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: 60050
    
  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: 18121
    
    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: 1391
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
Image insertion problem
Problem with ajax implementation using Jquery
Is it possible to put a scriptlet inside the href attribute of a <a> tag?
passing parameter
I want to insert normal data and image in one servlet but am getting one problem ?