File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to check entered value is of which primitive type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to check entered value is of which primitive type?" Watch "How to check entered value is of which primitive type?" New topic
Author

How to check entered value is of which primitive type?

Naresh BabuP
Greenhorn

Joined: Apr 05, 2009
Posts: 5
Hello,

How to check entered value is of which primitive type? Say, entered value is from command prompt.

regards,
Naresh
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Before thinking of anything, which primitive would you say "0" is ?


[My Blog]
All roads lead to JavaRanch
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689

In that case you can make Regex pattern and check if contains only number form [0-9] means int. If contains Alphabet from [A-Za-z0-9] and other special character then String. If input contains [0-9] with (DOT .) then float. you can set it according to your requirement.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Important question: what is "0"? Is it:
a) a byte
b) a short
c) a char
d) an int
e) a long
f) a float
g) a double
h) all of the above

These kinds of decisions are very important; do you always take int if possible, ignoring byte and short? Is char only every 1-character String that is not a digit?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Use Scanner:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Somebody else had a similar question recently: here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check entered value is of which primitive type?