• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Some String-like questions

 
Ranch Hand
Posts: 57
IntelliJ IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. While I understand StringTokenizer, per Java docs, is not recommended to be used, my instructors insist on requiring its use. Is each token considered data type String or StringTokenizer?

2. split() returns an array of strings, yet the length of an array cannot be increased (if I remember correctly) once it's been set. If I clear the previously split String array, and split another of the same name, will it allow a length large enough to accomodate the current number of elements? For example, say the first string splits into 3 elements. The next will be split into 5 elements. Will this generate an out of bounds exception or other error?
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brandt Charles:
1. While I understand StringTokenizer, per Java docs, is not recommended to be used, my instructors insist on requiring its use. Is each token considered data type String or StringTokenizer?



The type returned by nextToken() is String.

2. split() returns an array of strings, yet the length of an array cannot be increased (if I remember correctly) once it's been set. If I clear the previously split String array, and split another of the same name, will it allow a length large enough to accomodate the current number of elements? For example, say the first string splits into 3 elements. The next will be split into 5 elements. Will this generate an out of bounds exception or other error?



Each time you call split(), it will produce a new array. The size of the array doesn't change. You are correct that the size of an array cannot be increased once its created. However, a reference to an array can be assigned to refer to another array of that type as long as the reference isn't declared final.
[ July 05, 2006: Message edited by: Keith Lynn ]
 
Brandt Charles
Ranch Hand
Posts: 57
IntelliJ IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Keith. I think I'm going to try this with split()
 
Beware the other head of science - it bites! Nibble on this message:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic