byte to String Conversion Example Java

April 26, 2011 | String and StringBuffer
byte To String

We know earlier, parsing is the operation on strings to convert into data types. This parsing, we used in command-line arguments and User Password validation. Now we think the other way. Sometimes, it is required to convert data types to string; exactly opposite of parsing. For this purpose, the String class comes with valueOf() static method. valueOf() is overloaded to take any data type as parameter and converts into string; it converts even objects into strings.

The following program does the job of converting byte to string.
public class ByteToString
{
  public static void main(String args[])
  {
    byte b1 = 10;
    String str = String.valueOf(b1);
    System.out.println("byte b1 value in string form is " + str);
  }
}

byte to String Output screen on byte to String Example

The byte b1 is passed as parameter to valueOf() method. This method converts byte b1 to string form. Anywhere b1 is required as string, str can be used. For example, to display anything thing in TextField, it must be in string form. Now str can be displayed in TextField as follows.

t1.setText(str);

where t1 is an object of TextField.

A string can also be converted to byte, short, int, long, float, double, char and boolean.

Note: The other way, string to byte can be done in Java.

\============================================================================

Your one stop destination for all data type conversions

byte TO

short

int

long

float

double

char

boolean

short TO

byte

int

long

float

double

char

boolean

int TO

byte

short

long

float

double

char

boolean

float TO

byte

short

int

long

double

char

boolean

double TO

byte

short

int

long

float

char

boolean

char TO

byte

short

int

long

float

double

boolean

boolean TO

byte

short

int

long

float

double

char

String and data type conversions

String TO

byte

short

int

long

float

double

char

boolean

byte

short

int

long

float

double

char

boolean

TO String