Results 1 to 7 of 7
Thread: string program in java
- 12-16-2010, 05:21 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
string program in java
i have a program with string = "I Came I Saw I Left"
i want a program to
1> remove duplicates<like "I" o/p--->Came Saw Left>
2> output should be like I saw,I Left,I Came
public class StringTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s= "I came I saw I left";
String[] words = new String[16];
words = s.split(" ", 0);
for(int i=0;i<words.length;i++){
System.out.println("---word--"+words[i]);
}
}
}
- 12-16-2010, 05:25 PM #2
Did you have a question?
How To Ask Questions The Smart Way
- 12-16-2010, 05:30 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
in the mentioned below program i want the output
to be like
Came Saw Left
i.e i should remove all the "I" in the string declaration
public class StringTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String s= "I came I saw I left";
String[] words = new String[16];
words = s.split(" ", 0);
for(int i=0;i<words.length;i++){
System.out.println("---word--"+words[i]);
}
}
}
how can i acheive this???
- 12-16-2010, 05:33 PM #4
Check out the String API for useful functions.
String (Java Platform SE 6)
- 12-16-2010, 06:18 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 12-16-2010, 06:22 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 18
- Rep Power
- 0
i am geeing the same string output as declared
- 12-16-2010, 06:35 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Not as the same, but the words isn't it?
Similar Threads
-
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
program help: Extracting words from a string
By toad in forum New To JavaReplies: 1Last Post: 11-04-2007, 06:39 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks