my dog learned polymorphism
The moose likes Beginning Java and the fly likes Testing a arraylist for the same string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Testing a arraylist for the same string" Watch "Testing a arraylist for the same string" New topic

Testing a arraylist for the same string

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hello all i an array list with the following inside it

I want to be able to get the output like this
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.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeff Langr
Ranch Hand

Joined: May 14, 2003
Posts: 799
Use a set, which can contain no duplicates. See Set, HashSet, and perhaps TreeSet in java.util.

Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Ruben Steins

Joined: Nov 22, 2002
Posts: 15

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

Joined: Jun 09, 2003
Posts: 4632
Here's one way
I agree. Here's the link:
subject: Testing a arraylist for the same string
It's not a secret anymore!