Convert string to a short value
static short parseShort(String s)
- Parses the string argument as a signed decimal short.
static short parseShort(String s, int radix)
- Parses the string argument as a signed short in the radix specified by the second argument.
static Short valueOf(short s)
- Returns a Short instance representing the specified short value.
static Short valueOf(String s)
- Returns a Short object holding the value given by the specified String.
static Short valueOf(String s, int radix)
- Returns a Short object holding the value extracted from the specified String when parsed with the radix given by the second argument.
public class Main {
public static void main(String[] args) {
System.out.println(Short.parseShort("10"));
System.out.println(Short.parseShort("10",8));
System.out.println(Short.valueOf("10"));
System.out.println(Short.valueOf("10",8));
}
}
The output:
10
8
10
8
Home
Java Book
Essential Classes
Java Book
Essential Classes
Short:
- Short class
- Find out the min value, max value and size of Short types
- Create Short object with its constructor
- Convert Short to byte, double, float, int, long and short
- Decode a string to short value
- Convert string to a short value
- Reverse the bytes in a short
- Convert short value to string
- Compare two short values