• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between the two

 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know the difference between new String(byte[],encoding) and new String().getBytes(encoding).
Please explain.
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first one produces a String as the result. The second one produces a byte array as the result.

There are more differences, but you only asked for one.
 
Mahesh Bamane
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, you can go ahead and tell them all ;)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java™ Platform, Standard Edition 6 - API Specification.
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first takes a byte[] and creates a String with its contents. The second creates a new empty String, then retrieves its bytes in a specific encoding, then throws away this empty String. The byte[] should be empty.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic