• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

StringTokenizer and whitespace characters

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 450 it says in section Tokenizing with java.util.StringTokenizer:

StringTokenizer objects use whitespace characters by default as delimiters, ...


However on the java API of StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html) it says:

The tokenizer uses the default delimiter set, which is" \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character and the form-feed character.


I think they forgot to mention the other default delimiters...

(This post originated in the K&B7 errata thread)
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hester Willems,

First of all, a warm welcome to CodeRanch!

Hester Willems wrote:

The tokenizer uses the default delimiter set, which is" \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character and the form-feed character.


I think they forgot to mention the other default delimiters...


Or maybe characters like '\t', '\n', '\r', and '\f' are considered to be all whitespace characters as well, besides the (very obvious) space character.

In the Character class, you'll have a isWhitespace(char) method. So let's see what this method returns for these characters. Here's the code snippetOutput:


Here you'll find the javadoc of this method. And in the javadoc of the Pattern class, you'll see that those characters are considered a whitespace character as well. So every character of the default delimiter set is a whitespace character, so I think it's safe to say the statement in the study guide is spot-on.

Hope it helps!
Kind regards,
Roel
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic