• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

String Tokenizer

Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read a lot about string tokenizer and stream tokeniser. I was unable to figure out the differenr between them and what do we need it.
The only thing I came to know is it splits up the string with some delimiters.
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer breaks a String object into parts. It does this in the following way....
String sStr = new String("John,1,44,2,55,3,66");
// Breakin my string at the commas.
// Note that the tokenizer ignore the actual
// delimiter, in this case the ","
StringTokenizer tokens = new StringTokenizer(sStr,",");
// iterating through my tokens.
while (tokens.hasMoreTokens()) {
System.out.println("Token value: " + tokens.nextToken());
// This prints out the following:
// Token Value: John
// Token Value: 1
// Token Value: 44
// Token Value: 2
// Token Value: 55
// Token Value: 3
// Token Value: 66
Now a 'StreamToknizer' does the exact same thing as Above, BUT, instead of using a String obect is uses one of the InputStream objects like AudioInputStream, ByteArrayInputStream, FileInputStream, FilterInputStream, InputStream, ObjectInputStream, PipedInputStream, SequenceInputStream, StringBufferInputStream.
If you wanted to convert a stream to a 'string' you would have to get the byte array (which is what a Stream returns) and convert it into a string.
In a nutshell: the StreamTokenizer allows you to split information coming from an InputStream without going through the added hassle of converting it all into a byte array (byte[]) and then storing this into a String object.
Hope I didn't confuse you too much.
[This message has been edited by John Bateman (edited March 14, 2000).]
What does a metric clock look like? I bet it is nothing like this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic