Results 1 to 2 of 2
  1. #1
    vladimir is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default stringtokenizer + array problem

    Hi, this is my first post.. so plz don't shout at me so much :)

    I am spliting some text by using stringtokenizer and then i have to maka an array from those words... and i get some problems.. I am totally noob in java so... be patient :) plz. here is part of my code:

    Java Code:
    StringTokenizer st1 = new StringTokenizer(s,".,; ");
                  String words [];
                  words = new String[st1.countTokens()];
                 //words[0]= st1.nextToken();
                 int i=0;
           	  words[i] = st1.nextToken();
                  while (st1.hasMoreTokens()) {
                	  
    				System.out.println(st1.nextToken());  
    				
    	              
    			     //for  (int j=0; j<words.length; j++)System.out.println(words[i]);
                 // int i= 1;
       		   //  words[i++] = st1.nextToken();
    			     //int i=1;
    				 //words[i++] = st1.nextToken();  	
    				// System.out.println(words[1]); }
    		    
    				}
    All those comments are my 'tries' ... hehe

    I have no idea where or how to make an array from those words that i get them from stringtokenizer.. after making this array i have to check if first and last word is the same [that's why probably i need to make this array... ]

    Any help?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: stringtokenizer + array problem

    how to make an array from those words
    Several steps:
    1) create the array
    2) create an index for use with the array
    3) get the data
    4) assign the data to the array at the index
    5) increment the index to the next slot in the array

    Steps 3,4,5 are in a loop

Similar Threads

  1. Stringtokenizer phone number problem
    By artur in forum New To Java
    Replies: 2
    Last Post: 11-29-2011, 10:00 PM
  2. Phone number stringtokenizer problem
    By jacques5309 in forum New To Java
    Replies: 10
    Last Post: 11-14-2011, 03:12 AM
  3. formatting text: StringTokenizer, array
    By katiebear128 in forum New To Java
    Replies: 9
    Last Post: 11-06-2011, 02:36 AM
  4. Replies: 0
    Last Post: 05-12-2011, 08:04 PM
  5. Problem with delim in StringTokenizer
    By acp26b in forum New To Java
    Replies: 2
    Last Post: 01-15-2009, 03:44 AM

Posting Permissions

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