• 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

Converting an String to bytes

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I have come across an interesting piece of code and just want a confirmation of my understanding of it. If i have a string whicH i want to convert into a series of bytes using UTF-16 encoding i can use the String method getBytes by passing it the name of the encoding set to use.

I have found this piece of code that does the exact same thing.

I am persuming that the second piece of code will run faster than the first and as a result this is why someone can write it. I ran a basic test myself and my guess seems to be confirmed. Can anyone tell me if im correct and also why the second method is faster than the first.
thanks,
John
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second method is faster as it does not use the CharToByteConverter abstract factory to create a converter specific to the destination encoding.
Did you find very significant difference in your benchmark when running the JVM in server mode?
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try JDK 1.4? The character encoding stuff is much improved in 1.4.
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Beno�t d'Oncieu:
The second method is faster as it does not use the CharToByteConverter abstract factory to create a converter specific to the destination encoding.
Did you find very significant difference in your benchmark when running the JVM in server mode?


Ok thanks. I didnt get a change to run the JVM in server mode, just a quick test on my desktop where i called both pieces of code 1000 times and checked the time difference
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Landers:
Did you try JDK 1.4? The character encoding stuff is much improved in 1.4.



Well im stuck on 1.3.1 for this project but i must do some experimentation when i get some time.....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic