File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes difference between the two Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between the two" Watch "difference between the two" New topic
Author

difference between the two

Mahesh Bamane
Ranch Hand

Joined: Mar 12, 2008
Posts: 68
I would like to know the difference between new String(byte[],encoding) and new String().getBytes(encoding).
Please explain.


There is nothing like trying, either you do it or you don't.
SCJP 1.5
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

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

Joined: Mar 12, 2008
Posts: 68
Please, you can go ahead and tell them all ;)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Java™ Platform, Standard Edition 6 - API Specification.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between the two