• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for a String in ArrayList

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 20990
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic