Results 1 to 8 of 8
- 12-19-2010, 06:23 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
remove duplicate word in the string
import java.util.HashSet;
import java.util.Set;
public class StringTest {
public static void main(String[] args) {
String s= "I came I saw I left";
Set<String> s = new HashSet<String>();
for (String a : args)
if (!s.add(a))
System.out.println("Duplicate detected: " + a);
System.out.println(s.size() + " distinct words: " + s);
}
}
i am getting complier error..please help
i am trying to remove duplicate word in the string
input:"I came I saw I left"
i need output as :::"came saw left"
-
You need to post the error message and state what line is causing it. I also see that you have two variables with the same name, "s". That won't work.
edit: and do you really mean to loop through the command line arguments and ignore the String in the program? If so, I'd delete that String.
- 12-19-2010, 06:38 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 12-19-2010, 06:47 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
Hi
basically i was trying to eliminate duplicate values frm string...
i dnt knw where to declare the string variable
i got this code from java website
the error will be an obvious one...
that it has been defined already....
-
Please do not use non-standard abbreviations in your posts. It may seem like nit-picking, but it makes your posts hard to read, and since computer programming is all about precision, and one little spelling or capitalization error can spell doom, it is in your best interest to communicate your questions clearly. Also, many of the volunteers here don't speak English as a primary language and will have great difficulty understanding your post. You can edit the post above by clicking on the edit button to the lower right of the post.
Thanks for your cooperation.
Regarding your problem, don't borrow code that you don't understand else you'll end up with "Franken code". Instead I suggest that you start over and just write the method yourself from scratch.
Luck.
- 12-19-2010, 06:53 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
import java.util.HashSet;
import java.util.Set;
public class StringTest {
public static void main(String[] args) {
String s= "I came I saw I left";
Set<String> s = new HashSet<String>();
for (String a : args)
if (!s.add(a))
System.out.println("Duplicate detected: " + a);
System.out.println(s.size() + " distinct words: " + s);
}
}
where should i declare the syntax marked in orange it so that i get the following output....
input:"I came I saw I left"
i need output as :::"came saw left"
-
- 12-19-2010, 07:16 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
longest word present in a string
By somnath6088 in forum New To JavaReplies: 4Last Post: 11-09-2010, 05:43 PM -
how to remove word words from txt file?
By amroosobhy in forum New To JavaReplies: 3Last Post: 10-08-2010, 01:49 PM -
How to Remove Duplicate object from collection
By santhoskumara in forum Advanced JavaReplies: 4Last Post: 08-04-2010, 07:07 PM -
Remove duplicate lines from a text file
By Dirt.Diver in forum New To JavaReplies: 15Last Post: 06-25-2008, 02:08 PM -
random string are duplicate
By googgoo in forum New To JavaReplies: 3Last Post: 04-03-2008, 10:01 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks