Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to find out the datatype

 
shyam sunder prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
how to find out the data type based on data.
 
Stephan van Hulst
Bartender
Posts: 6646
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it depends on the data. Can you be more specific?
 
shyam sunder prasad
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose,

there is a string s="122.2". so i want to convert it to float type. or based on the date i want to do different operation.

so, is there any method is java to find out what the data type is?
 
Stephan van Hulst
Bartender
Posts: 6646
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, you want Java to interpret your data? No, Java can't do this. You will have to do it yourself. If you have a String and you know ahead of time that it represents a number, you can call a method like Integer.parseInt() to convert the String to an int.

Do you have a specific reason you're asking this question?
 
Campbell Ritchie
Marshal
Posts: 53094
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably Google and find a regular expression for floating-point numbers and for integers in a few seconds. That might work. Some of the expressions here are mistaken, but you have a good chance of finding something useful there.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!