
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert String to byte array
Here is our string.
String str = "Asia is a continent!";
Now let us use a byte array and the getBytes() method to fulfill our purpose.
byte[] byteVal = str.getBytes();
Now, if we will get the length of the array, it would return the length as shown in the complete example below −
Example
public class Demo { public static void main(String args[]) { String str = "Asia is a continent!"; System.out.println(str); // converted to byte array byte[] byteVal = str.getBytes(); // getting the length System.out.println(byteVal.length); } }
Output
Asia is a continent! 20
- Related Questions & Answers
- Java Program to convert byte[] array to String
- Java Program to convert byte to string
- Java Program to convert string to byte
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- Java program to convert Byte array to IP Address
- Convert byte to String in Java
- How to convert hex string to byte Array in Java?
- How to convert a byte array to hex string in Java?
- How to convert byte array to string in C#?
- How to convert a byte array to a hex string in Java?
- Java Program to create Stream from a String/Byte Array
- How to convert BLOB to Byte Array in java?
- How to convert Byte Array to BLOB in java?
- How to convert Byte Array to Image in java?
Advertisements