Tuesday 29 March 2016

Java Tutorial : Java String [getBytes(Charset charset) method]


Click here to watch in Youtube :
https://www.youtube.com/watch?v=OewKcyeYqVg&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java String [getBytes(Charset charset) method] 
GetBytesDemo.java
/*
 * public byte[] getBytes(Charset charset)
 * 
 * Parameters: 
 * ---------- 
 * charset - The Charset to be used to encode the
 * String
 * 
 * Returns: 
 * ------- 
 * The resultant byte array
 */
public class GetBytesDemo
{
    public static void main(String[] args)
    {
        String str = "Hi";

        java.nio.charset.Charset charSet = java.nio.charset.Charset
                .forName("ASCII");
        
        byte[] byteArray = str.getBytes(charSet);
        System.out
                .println("byteArray of \"Hi\" with charsetName \"ASCII\" = "
                        + byteArray);
        for (byte b : byteArray)
        {
            System.out.println(b);
        }

    }
}
Output
byteArray of "Hi" with charsetName "ASCII" = [B@6ae40994
72
105
Refer:

http://unicode-table.com/en/

https://en.wikipedia.org/wiki/List_of_Unicode_characters

Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/StringDemo_getBytes_charset_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StringDemo_getBytes_charset_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/219b10088440d75a7105e6bff5bbab9e88ad9a80/BasicJava/StringDemo_getBytes_charset_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment