Java Convert Short to String Example

In this article, we will show you how to convert Java wrapper class Short or primitive type short to String code examples. There are different ways we can wrapper class Short or primitive type short to String.
In this example, we will demonstrate converting wrapper class Short or primitive type short to String in 2 ways.
  1. Convert using String.valueOf(s)
  2. Convert using Short.toString(s)
/**
 * Class to Convert Short To String Example
 * @author javaguides.net
 *
 */

public class ConvertShortToStringExample {
 public static void main(String[] args) {

  /*
   * Method 1: using valueOf() method of String class.
   */
  short s = 10;
  String shortStr = String.valueOf(s);
  System.out.println("Convert short to string using valueOf method ::" + shortStr);

  /*
   * Method 2: using toString() method of Short class
   */
  String shortStr1 = Short.toString(s);
  System.out.println("Convert short to string using Short.toString method ::" + shortStr1);
 }
}
Output:
Convert short to string using valueOf method ::10
Convert short to string using Short.toString method ::10

Related Java String Conversion Examples

Comments