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.
/**
* 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
- Java Convert Integer to String Example
- Java Convert Float to String Example
- Java Convert Double to String Example
- Java Convert Short to String Example
- Java Convert Long to String Example
- Java Convert Character to String Example
- Java Convert Byte to String Example
- Java Convert Boolean to String Example
Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours
Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course
Comments
Post a Comment