Results 1 to 6 of 6

Thread: StringTokenizer problem in java

  1. #1
    Join Date
    Mar 2010
    Posts
    197

    StringTokenizer problem in java

    Hello
    Here I want a chain splitter, I use it StringTokenier:
    Here is my code
    Code:
      public List getListUnderCountries(String Countries){
        	String str =";";
        StringTokenizer strtok = New StringTokenizer(Countries, str);
        List lst = New ArrayList();
        	while (strtok.hasMoreTokens()){
        		System.out.print(strtok.nextToken());
        lst.add(strtok.nextToken(str));
        	}    	
        	return lst;
        }
    But i get an error in that, so, if you have any idea regarding this then please let me know. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: StringTokenizer problem in java

    Hello,
    I think if you write the below line in your code, it will be more effective and will work for sure, because I have tested it.
    Just insert this line your code
    Code:
    String[] = countryArray cntr.split(";");
    I think you can try this, because when I had used this in my code, my code was compiled without any errors.

  3. #3
    Join Date
    Nov 2009
    Posts
    347

    Re: StringTokenizer problem in java

    Hello,
    Have a look at the following code, this may help you
    Code:
    public List getListUnderCountries (String countries) (
        String str =";";
        StringTokenizer strtoken = new StringTokenizer (Countries, str);
        CountriesList list = new ArrayList ();
        while (strtoken.hasMoreTokens ()) (
                     String t = strtoken.nextToken ()
        System.out.println (t);
        lst.add (t);
        	)
        lst return;
        )

  4. #4
    Join Date
    Nov 2009
    Posts
    518

    Re: StringTokenizer problem in java

    Hello,
    Every time you call the method
    Code:
    nextToken ()
    you read the value and you orbits.
    Code:
    System.out.println (strtoken.nextToken ())
    you and you posters EN orbits
    Code:
    cntrlst.add (strtoken.nextToken (delim))
    you put in AT and you cntrlst orbits.
    Code:
    System.out.println (strtoken.nextToken ())
    you and you posters OF orbits. I hope you are understanding what i am trying to say.

  5. #5
    Join Date
    Nov 2009
    Posts
    330

    Re: StringTokenizer problem in java

    Hello,
    Better to create a temporary variable.
    Here is what I am trying to say
    Code:
    String strTemp = null;
    while (strtoken.hasMoreTokens()){
       strTemp = strtoken.nextToken();
       / / Salaries
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: StringTokenizer problem in java

    Hello,
    I think you can replace the below in your code, this will make your code more efficient and effective.
    And the code will now look something like this.
    Code:
    public List getListUnderCountries(String Countries){
             String[] arr = cntr.split(";");
             return Arrays.asList(arr);
    }

Similar Threads

  1. Problem in StringTokenizer
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 04:43 AM
  2. StringTokenizer class of java
    By Mithun Seth in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 01:12 PM
  3. Problem with StringTokenizer
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 07-02-2010, 01:47 AM
  4. FileInputStream and StringTokenizer
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 12:55 PM
  5. How to use StringTokenizer to split a string in java?
    By Baazigar in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 09:50 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,318,941.25451 seconds with 17 queries