java.lang.Number has following subclasses:
BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short
I am exploring datatypes and I am confused when to use Short and when to use Integer. It appears to me that both can save same values.
Thanks in advance.
Short s = 22;
Integer i = 23;
Yes, up to the max value for the short data type. Then you have to use int up until you reach its max value. Then you have to use long.
System.out.printf("max short value = %d%n" +
"max int value = %d%n" +
"max long value = %d%n",
Great. That was helpful.
So using Integer for values less than 32767 is waste of memory.
If all your doing is storing and looking up the data, a short or byte is just fine. However, if you do any other processing with a non int type, it must be converted to an int which causes a slow down in calculations. This is further explained at.
Java Primative Speed