Results 1 to 2 of 2
  1. #1
    mew
    mew is offline Member
    Join Date
    Nov 2007
    Posts
    70
    Rep Power
    0

    Default bytearray to string conversion

    I converted a String into a ByteArray. Then I tried to convert it back to string using toString() method. The output is not as expected. Please highlight the problem area:


    Java Code:
    		String str = "Java World for 1.4";
    		byte bArray[] = new byte[str.length()];
    		
    		bArray = str.getBytes();
    		
    		String bString = bArray.toString();
    		
    		System.out.println("Byte array converted to string: " + bString);
    Output:

    Java Code:
    Byte array converted to string: [B@3e25a5

  2. #2
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Java Code:
    String bString = new String(bArray);
    arrays never gives content in toString() .. what's working there is plain Object.toString()
    Last edited by roots; 01-28-2008 at 10:41 AM.
    dont worry newbie, we got you covered.

Similar Threads

  1. Reading a File into ByteArray
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:19 PM
  2. Method for String to int conversion
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:35 PM
  3. String to Integer conversion
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 03:59 PM
  4. Replies: 0
    Last Post: 11-27-2007, 10:23 AM
  5. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 07:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •