2:55 am - Tuesday April 23, 2019

String Example Program for getBytes(Charset charset)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@AUTHOR: candid java
@DESCRIPTION: Copy the contents of the String to a byte array using the given charactersetencoding.
*/
public class GetBytesCharset1
{
    public static void main(String[] args)
    {
    try
    {
         String str = "hello java";
         byte[] arr = str.getBytes("ASCII");//:Copy the contents of the String to a byte array using the ASCII
          String newStr = new String(arr);
          System.out.println("bytes for the given string is ="+arr);
      }
    catch (Exception ex)
    {
    }
    }
}

OUTPUT:
bytes for the given string is =[B@42e816]

BACK

Filed in: Z-A All Java Codes

Comments are closed.