Results 1 to 5 of 5
  1. #1
    kgkamaraj is offline Member
    Join Date
    Feb 2010
    Posts
    9
    Rep Power
    0

    Default convert byte array into char array

    HI,
    Can any one know how to convert byte array into char array.

    For example :

    byte buf[]=teststr.getBytes();

    Note:
    buf is byte array. I need to convert this into char array.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    8

    Default

    Java Code:
    new String(buf).toCharArray();
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    As I said here

    Why use getBytes? Why don't you use toCharArray? In any case, the easiest way (although not necessarily the most effecient) is to do
    Java Code:
    new String(byte[]).toCharArray()
    ;-) Phil

  4. #4
    muneeb is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: convert byte array into char array

    can any1 tell me how to convert char[] array into byte[]...?

    Thanks.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,048
    Blog Entries
    7
    Rep Power
    23

    Default Re: convert byte array into char array

    Quote Originally Posted by muneeb View Post
    can any1 tell me how to convert char[] array into byte[]...?

    Thanks.
    Read the API documentation for the String class and please start your own thread and don't resurrect an old thread.
    (I'm closing this thread)

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  2. How Convert a Byte array to a image format
    By perlWhite in forum New To Java
    Replies: 2
    Last Post: 08-23-2009, 08:11 PM
  3. How Convert a Byte array to a image format
    By perlWhite in forum Advanced Java
    Replies: 1
    Last Post: 08-22-2009, 07:05 PM
  4. String array to byte array?!
    By Joe2003 in forum Advanced Java
    Replies: 5
    Last Post: 02-28-2009, 07:09 AM
  5. Replies: 9
    Last Post: 09-11-2008, 02:51 AM

Posting Permissions

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