Convert string to a short value

ReturnMethodSummary
static shortparseShort(String s)Parses the string argument as a signed decimal short.
static shortparseShort(String s, int radix)Parses the string argument as a signed short in the radix specified by the second argument.
static ShortvalueOf(short s)Returns a Short instance representing the specified short value.
static ShortvalueOf(String s)Returns a Short object holding the value given by the specified String.
static ShortvalueOf(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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.