Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java Language
Expertise: Beginner
May 31, 1998

StringTokenizer

Question:
After:

StringTokenizer st = new StringTokenizer(line);
Do I have to write:

String key = new String(st.nextToken());
or is it enough to write:

String key = st.nextToken();

Answer:
It is sufficient to write

String key = st.nextToken();
The nextToken() method will allocate a new String containing the next token and return it. Creating a copy of that String is redundant and wastes memory and cycles.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date