Java Tutorial with Java Code Examples

Java Basics | String | Date | Collection | Java Map | Java Util | File I/O | XML | Threading | Network | i18n | Misc
Java Swing | JDBC | Servlet | JSP | JSTL | JMS | EJB | JPA | JSF | Struts | Spring | Hibernate
Web Services | Java PDF | JUnit | Ant | HTML | JavaScript | Apache | Tomcat | SQL | T-SQL | PL/SQL | MySQL

Java Basics

Introduction

Data Types and Arrays

Get User Input

Data Type Conversions

Control Flow

Handling Exception

 

  Java Basics » Data Type Conversions » Convert String to byte

  Java Code Example:  StringToByteConverter.java  Download Sample Source Code

/*
 * Copyright © 2008 - 2009 it.ibluespace.com. All rights reserved.
 */
public class StringToByteConverter { public static void main(String args[]) { String str = "58"; //approach 1: to convert String to byte byte b1 = Byte.parseByte(str); System.out.println( "b1 = " + b1 ); //approach 2: to convert String to byte byte b2 = Byte.valueOf(str); System.out.println( "b2 = " + b2 ); } }
 Download Source Code: StringToByteConverter.java

The command executed and output produced:


E:\JavaEECoding\>java StringToByteConverter
b1 = 58
b2 = 58

Search for Java code examples on this site

 
 

Resources

Java Tutorial

Java World

Java SE 6 API Doc


Terms of Use  |  License  Copyright 2008-2009 it.ibluespace.com. All rights reserved.  | 
All other trademarks are the property of their respective owners.