How to convert short to String in java


In this core java tutorial we will learn how to convert short primitive type to String in java and convert short object to String with program and examples in java. We will  also understand  When to use convert String to short primitive type and when when to convert String to short object in java.





Programs to convert short to String in java -
  • Program/Example 1 to How to convert short primitive type to String  in java.
  • Program/Example 2 to How to convert short object to String in java


Program/Example 1 to How to convert short primitive type to String  in java.

String.valueOf(short) method converts short primitive type to String  in java.

package convertShortToStringPkg;
public class ConvertShortToStringExample1 {
   public static void main(String[] args) {
         
          short s = 12;
          String string = String.valueOf(s);
          System.out.println("string = "+string);
  
   }
}
/*OUTPUT
string = 12

*/




Program/Example 2 to How to convert short object to String in java

toString() method of java.lang.Short class convert short object to String in java.

package convertShortToStringPkg;
public class ConvertShortObjectToStringExample2 {
   public static void main(String[] args) {
          Short shortObject = 12;
          String string = shortObject.toString();
          System.out.println("string = "+string);
  
   }
}
/*OUTPUT
string = 12
*/



Summary -

In this core java tutorial we learned conversion of short primitive type to String in java and convert short object to String with program and examples in java. We also understood  when to use convert String to short primitive type and when when to convert String to short object in java.




Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy(JMSE) on facebook, following on google+ or Twitter.


RELATED LINKS>

Collection - List, Set and Map all properties in tabular form



No comments:

Post a Comment