Meaningless Drivel is fun!*
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
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: 18541
    
    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: 19653
    
  18

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
 
Similar Threads
Difference Between the String s = "String "; and String s = new String("String");
difference between String a ="abcd" and String b= new String ("abcd")
empty string question
difference between poll memory and non-poll memory?
getting parameters from the URL