Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing a arraylist for the same string

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all i an array list with the following inside it

I want to be able to get the output like this
ben
Names
name
mum
so what should happen, is that it test the arraylist for dublicates and only pulls out one of each. if you understand what I mean.
Thanks
Ben
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? Which part is giving you trouble?
When asking folks a question, taking a minute to first explain things to your Cardboard Analyst and to think about Asking a Good Question is time well spent.
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a set, which can contain no duplicates. See Set, HashSet, and perhaps TreeSet in java.util.
-Jeff-
 
Ruben Steins
Greenhorn
Posts: 15
Chrome IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make an array in which you copy the unique elements and print its contents.
But, Dirk is right: Give these problems some thought yourself, that way you'll learn a lot faster...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one way
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic