See the Tutorial List

Short Class


Below are the Methods of Short class and their example.

1. toString()

Syntax:

	
public String toString(short b)
	

Example:

	
public class ShortDemo1 
{ 
    public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	
	System.out.println("toString(a) = " + Short.toString(a));
	}
}
	

short-class


2. valueOf()

Syntax:

	
public static Short valueOf(short b)
	

Example:

	
public class ShortDemo1 
{ 
    public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	Short x = Short.valueOf(a); 
System.out.println("valueOf(a) = " + x); 
        x = Short.valueOf(b); 
System.out.println("ValueOf(b) = " + x); 
        x = Short.valueOf(b, 6); 
System.out.println("ValueOf(b,6) = " + x); 
	}
}
	

short-class-example


3. parseShort()

Syntax:

	
public static short parseShort(String val, int radix)
            throws NumberFormatException
	

Example:

	
public class ShortDemo1 
{ 
    public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	
	Short x = Short.parseShort(b); 
System.out.println("parseShort(b) = " + x);  
        x = Short.valueOf(b, 6); 
System.out.println("parseShort(b,6) = " + x); 
	}
}
	

short-class-example


4. decode()

	
public static Short decode(String s)
             throws NumberFormatException
	

Example:

	
public class ShortDemo1 
{ 
    public static void main(String[] args)  
	{ 
        String a = "25"; 
        String b = "007"; 
        String c = "0x0f"; 

        Short x = Short.decode(a); 
System.out.println("decode(45) = " + x); 
        x = Short.decode(b); 
System.out.println("decode(005) = " + x); 
        x = Short.decode(c); 
System.out.println("decode(0x0f) = " + x); 
	}
}
	

short-class-example


5. byteValue()

Syntax:

	
public byte byteValue()
	

6. shortValue()

Syntax:

	
public short shortValue()
	

7. intValue()

Syntax:

	
Syntax : public int intValue()
	

8. longValue()

Syntax:

	
public long longValue()
	

9. doubleValue()

Syntax:

	
public double doubleValue()
	

10. floatValue()

Syntax:

	
public float floatValue()
	

Example:

	
public class ShortDemo1 
{ 
    public static void main(String[] args)  
	{ 
	short a = 75; 
        Short obj = new Short(a);
	System.out.println("bytevalue(obj) = " + obj.byteValue()); 
System.out.println("shortvalue(obj) = " + obj.shortValue()); 
System.out.println("intvalue(obj) = " + obj.intValue()); 
System.out.println("longvalue(obj) = " + obj.longValue()); 
System.out.println("doublevalue(obj) = " + obj.doubleValue()); 
System.out.println("floatvalue(obj) = " + obj.floatValue()); 
	}
}
	

short-class-example


11. hashCode()

Syntax:

	
public inthashCode()
	

Example:

	
public class ShortDemo1 
{ 
   public static void main(String[] args)  
	{ 
        short a = 45;
	Short obj = new Short(a);
	
	int x =obj.hashCode(); 
System.out.println("hashcode(obj) = " + x); 
	}
}
	

short-class-example


12. equals()

Syntax:

	
public boolean equals(Object obj)
	

Example:

	 
public class ShortDemo1 
{ 
   public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	
	boolean z = obj.equals(obj1); 
System.out.println("obj.equals(obj1) = " + z); 
	}
}
	 

short-class-example


13. compareTo()

Syntax:

	
public intcompareTo(Short b)
	

Example:

	
public class ShortDemo1 
{ 
   public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	
	int z = obj.compareTo(obj1); 
System.out.println("obj.compareTo(obj1) = " + z); 

	}
}
	

short-class-example


14. compare()

Syntax:

	
public static int compare(short x,short y)
	

Example:

	
public class ShortDemo1 
{ 
   public static void main(String[] args)  
	{ 
        short a = 45;
	String b ="25";
	Short obj = new Short(a);
	Short obj1 = new Short(b);
	int z = Short.compare(obj, obj1); 
System.out.println("compare(obj, obj1) = " + z); 
	}
}
	

short-class-example


15. reverseBytes()

Syntax:

	
public static short reverseBytes(short val)
	

Example:

	 
public class ShortDemo1 
{ 
   public static void main(String[] args)  
	{ 
        short a = 25;
	System.out.println("Short.reverseBytes(a) = " + Short.reverseBytes(a)); 
	}
}
	 

short-class-example