File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Regarding String, int

Edward Durai
Ranch Hand

Joined: Oct 09, 2004
Posts: 223

Consider I have

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

Thank You<br />Edward
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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.
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:
[ 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

Joined: Nov 03, 2006
Posts: 28
This may help
Integer.parseInt("2 ");
}catch(NumberFormatException e)
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:
subject: Regarding String, int
It's not a secret anymore!