wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to print a String with out duplicates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to print a String with out duplicates" Watch "How to print a String with out duplicates" New topic
Author

How to print a String with out duplicates

Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51
Hi,
What I am asking is if String s="ABABAGTREE" and I what to this string with out duplicates that is output should be ABGTRE.How can I get it?


Thanks in Advance.
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
You can use LinkedHashSet Collection class.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Write a simple loop to get each char from the input string and save it in the output string if its not already saved.
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
I think using collection classes is better as compared to writing loops. Loops are going to be very expensive in this case.
Rahul Noel
Ranch Hand

Joined: Jul 18, 2008
Posts: 51
Sorry, I did get you guys could you explain with code.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Originally posted by Jai Sriram:
Sorry, I did get you guys could you explain with code.
No, please show us what code/pseudocode you would use. You learn a lot more if you show us what you have already achieved and we comment on it.

And this is beginning to look like a beginner's question.
 
wood burning stoves
 
subject: How to print a String with out duplicates
 
Similar Threads
List with out duplicates
Duplicates in Collections-Confused!!
array
Showing resultSet
Quick == question