Results 1 to 7 of 7
  1. #1
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default 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]);
    }
    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default

    Did you have a question?

    How To Ask Questions The Smart Way

  3. #3
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    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???

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,038
    Rep Power
    10

    Default

    Check out the String API for useful functions.

    String (Java Platform SE 6)

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by katturv View Post
    how can i acheive this???
    Did you compile and run your code? If so whats happen?

  6. #6
    katturv is offline Member
    Join Date
    Oct 2010
    Posts
    18
    Rep Power
    0

    Default

    i am geeing the same string output as declared

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  2. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  3. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  4. program help: Extracting words from a string
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 07:39 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •