Example of getBytes() method of String class in java.

Example of getBytes() method of String class in java.


Posted in : Core Java Posted on : November 11, 2010 at 6:00 PM Comments : [ 0 ]

In this section, you will see the use of getBytes() method of String class in java.

Example of getBytes() method of String class in java.

In this java example, we will explain about the getBytes() method of String class in java. The getBytes(..) method encodes this string into a sequence of bytes using the platform's defaults charset, after encoding this string's bytes store the bytes into byte arrays.

Code:
GetBytesMethod.java
public class GetBytesMethod {
      public static void main(String[] args)   {
	// Create a string
	String str="devmanuals";
	// Display a string
	System.out.println("Given string : "+str);
	// Get bytes of strings
	byte[] stringByte=str.getBytes();
	// Display byte of string
	System.out.println("Byte value of string : "+stringByte);
    }
} 
Output:
C:\>javac GetBytesMethod.java 
C:\>java GetBytesMethod
Given string : devmanuals
Byte value of string : [B@19821f

Download this code.

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics