Results 1 to 4 of 4
Thread: Short/Integer
- 11-30-2007, 05:13 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 70
- Rep Power
- 0
Short/Integer
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.
Java Code:Short s = 22; Integer i = 23;
- 12-01-2007, 02:02 AM #2
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.
Java Code:System.out.printf("max short value = %d%n" + "max int value = %d%n" + "max long value = %d%n", Short.MAX_VALUE, Integer.MAX_VALUE, Long.MAX_VALUE);
- 12-01-2007, 10:41 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 70
- Rep Power
- 0
Great. That was helpful.
So using Integer for values less than 32767 is waste of memory.
- 12-06-2007, 10:28 PM #4
Member
- Join Date
- Dec 2007
- Location
- So Cal
- Posts
- 4
- Rep Power
- 0
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 SpeedLast edited by comando2929; 12-06-2007 at 10:36 PM. Reason: add signiture
Similar Threads
-
Integer Usage
By bluegreen7hi in forum New To JavaReplies: 11Last Post: 01-24-2008, 09:54 AM -
why doesn't this short applet work?
By kim85 in forum New To JavaReplies: 1Last Post: 01-20-2008, 09:43 PM -
VeryLong Integer.. help
By hey in forum New To JavaReplies: 4Last Post: 12-14-2007, 10:48 PM -
Short key for getting list of opened classes in Eclipse
By Java Tip in forum Java TipReplies: 0Last Post: 12-04-2007, 12:11 PM -
Integer vs int
By bugger in forum New To JavaReplies: 1Last Post: 11-14-2007, 10:13 PM
Bookmarks