I am trying to store the 10 digit mobile number in int, but it is saying that its out of range, how can i store in in开发者_StackOverflow社区t, any help pls
There is no semantic value in storing it as a number - you won't be doing any numerical operations on it. You should store the value as a string.
A mobile number might start with a 0 (zero) therefore I wouldn't advice to store it as a number. My advice would be to store it as a String. Otherwise you should use a long.
What about a proper TelephoneNumber type class:
public interface TelephoneNumber
A simple re-usable entity class that defines attributes of a telephone number.
You'd better use String, but you can also use long or BigInteger. But using String will allow you to store dashes or spaces between numbers.
Mobile numbers uses and E.164 numbering format for telephone or digital communications. You will have to use Strings as valid characters such as "+"/"-" can be found in mobile numbers.
Use a String, for for proper semantics I would wrap it in your own MobileNumber class.
Did you have a look at Java's BigInteger? Two possible references are:
- Oracle BigInteger
- Java Notes BigInteger
use Long
or String
instead of Integer
. Or give us some code examples for what you are trying to do.
精彩评论