English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
using thevalueOf()
method to convert a string to bytes. First, let's have a string.
String str = "65";
Now, using thevalueOf()
The method converts a string to bytes.
byte res = Byte.valueOf(str);
Let's see the complete example.
public class Demo { public static void main(String[] args) { String str = "65"; System.out.println("String: " );+str); byte res = Byte.valueOf(str); System.out.println("Byte: " );+res); } }
Output Result
String: 65 Byte: 65