aspose file tools*
The moose likes Beginning Java and the fly likes Regarding String, int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding String, int" Watch "Regarding String, int" New topic
Author

Regarding String, int

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
Hello,

Consider I have
e.g

String str = "Test INPUT";
int it = 44;

How can I check String "str" is a string type
integer "it" is int type.

Please let me know.
Thanking You
Regards,
edward


Thank You<br />Edward
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42919
    
  68
I don't understand what you're asking. You know that str is a String, because you have defined it that way.

If you have an Object reference "str", you can check whether it is a String via "str instanceof String", which returns a boolean.

Can you give us some more context about the problem you're trying to solve?
[ August 01, 2007: Message edited by: Ulf Dittmer ]
Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223
consider i have one text box,

If I enter any value,

for e.g if i enter 100, i want to see in console, "integer value"
if i enter text, it should display "string value"
if i enter date, it should display "date".

Please let me know
Thanking You.
Regards,
Edward
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
When you enter text into a text-box, that text is represented as a String, always. You could write code that examines that String and decides whether it makes sense to parse that String into a Date, or an int, or some other type.

See also:
Integer.parseInt()
DateFormat.parse()
[ August 01, 2007: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ashwin Sharma
Greenhorn

Joined: Nov 03, 2006
Posts: 28
hi....
This may help
try{
Integer.parseInt("2 ");
System.out.println("Integer");
}catch(NumberFormatException e)
{
System.out.println("String");
}
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Edward Durai:

String str = "Test INPUT";
int it = 44;


What do you give me to solve this question ?

If you give me a java object reference and ask me whether its pointing to String object or a int primitive , then I would say its String as reference to String object cannot contain int primitive.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding String, int