Checking wheter is "int" or "String"

Hi..
I would like to know is there a way to know if an attribute type is int or String while executing my application.
I heard "why do you wanna know?", that is just because this attribute belongs to another class and I'm gonna use it in every class. Later it's possible this attribute will change it's type so I would provide some if statements now, for don't have trouble with it later.
Thanks in advance.

Hi..
I would like to know is there a way to know if an
attribute type is int or String while executing my
application.
I heard "why do you wanna know?", that is just because
this attribute belongs to another class and I'm gonna
use it in every class. Later it's possible this
attribute will change it's type so I would provide
some if statements now, for don't have trouble with it
later.
Thanks in advance.What do you mean by "attribute type"?
How will it change its type? - if you change a variable type from int to String or vice versa, then code that uses it won't compile anyway.
Are you doing something unusual with reflection? If you are, could you post some code that demostrates what you actually want to do?

Similar Messages

  • Checking a value...String OR int

    checking a value...String OR int
    how to check a given value whether it is a String OR int
    if(jTextField1.getText()...) is a String
         System.out.println("String");
    else //if it an int
         System.out.println("int");
    How can i check this...
    pls,tell.

    getText of JTextField ALWAYS returns a String.
    You can do this to see if it could be interpreted as an int:
    String theText = jTextField1.getText();
    try
       int theInt = Integer.parseInt(theText);
       System.out.println("int");
    catch (NumberFormatException ex)
       System.out.println("String");
    }If it isn't in a form that can be parsed as an int, you will get an exception and the catch block will get executed.

  • Finding whether int or String

    I have a string variable and I have to find whether the value of the variable is
    number or characters.
    How can I do it in java?
    I was thinking of casting the variable to integer and if true then the value
    is integer, if false then string. I think this is not a good way of doing it?
    any idea. thanks.

    This is what i did, and its not showing any error at the moment.
    Is the following right way to do it
    > if(somevariable.getClass().toString()).equals("java.lang.String")){
    }else{
    That's not the way to do it because your 'somevariable' is a String.
    Either check every character in that string for being a digit or not, or
    let the Integer class do the dirty work:try {
       int theValue= Integer.parseInt(somevariable);
       // yes, it succeeded, so it was an int ...
    catch (NumberFormatException nfe) {
       // nope, the string didn't represent an integer number
    }kind regards,
    Jos

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • Conversion of int to String

    hi,
    Do someone know which way of converting the int to String is better? In term of performance and other issues in the handset:
    1. int a = 5;
    String b = a + "";
    2. int a = 5;
    String b = String.valueOf(a);
    Thank you!

    Hi,
    The second method is better. Because for the first method 3 String objects will be created.

  • Converting int to String

    How can we convert from int to String?
    Ex:
    int i = 5;
    Then i need that 5 in String format....
    Message was edited by:
    kiran_panga

    String.valueOf(i)
    According to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
    public static String valueOf(int i)
    Returns the string representation of the int argument.

  • Convert from int to String

    Hi, may i know how to convert from int to String??
    For instance, i've>>
    int i = 0;
    i++;
    String temp = i.toString();
    [Need to convert the int to String here. Am i doing the convertion correctly?? Pls correct me. Thanks!]

    Hi, may i know how to convert from int to String??
    For instance, i've>>
    int i = 0;
    i++;
    String temp = i.toString();
    [Need to convert the int to String here. Am i doing
    the convertion correctly?? Pls correct me. Thanks!]String temp = "" + i;

  • How to convert from int to string

    Can anyone help me on how to convert int to string?
    Thanks,
    Q

    int i = 3
    String S = i + ""
    i will be promoted to String automatically when the above expression is evaluated

  • Checking the length of a string in sapscript

    Is there a way to check the length of a string in sapscript?
    What I want to do is, if the length of two strings is greater than a certain ammount, truncate the string.
    But I don't know if is possible inside the sapscript

    Never mind, I did it with a perform instead

  • Convert an int in string

    I wrote this code to convert an int in string but is failed.
    Someone might help me. thanks
    String UID="select max(right(CodiceUtente,4)) from Utenti";
         ResultSet rs=st.executeQuery(UID);
         int massimo=rs.getInt("CodiceUtente") + 1;
              //massimo deve essere trasformato in una stringa. Come si fa?
         String maxim =toString();
    my email is [email protected]

    Try this one: String maxim = toString(massimo).
    Find out more from the API (hope it accepts this long
    URL that should point directly to the right place) :
    http://www.ttu.ee/it/vorgutarkvara/wai4040/jdkdoc/jdk1.
    2.2/docs/api/java/lang/String.html#toString()

  • Ints to Strings

    Can someone please tell me how I can convert an 'int' into a 'String'??
    The problem i am having is that i want to use some 'int' values and display them in a GUI TextField but I cant coz they are ints and a TextField only accepts Strings.
    So i want to be able to use the setText( ) method to do this after the conversion.
    Thanx.
    [K]

    then you look up javadocs,
    Integer:
    valueOf
    public static Integer valueOf(String s)
    throws NumberFormatException
    Returns an Integer object holding the value of the specified String. The argument is interpreted as representing a signed decimal integer, exactly as if the argument were given to the parseInt(java.lang.String) method. The result is an Integer object that represents the integer value specified by the string.
    In other words, this method returns an Integer object equal to the value of:
    new Integer(Integer.parseInt(s))
    Parameters:
    s - the string to be parsed. Returns:
    an Integer object holding the value represented by the string argument. Throws:
    NumberFormatException - if the string cannot be parsed as an integer.
    intValue
    public int intValue()
    Returns the value of this Integer as an int.
    Specified by:
    intValue in class Number
    Returns:
    the numeric value represented by this object after conversion to type int.
    String:
    suggestions above.

  • How to check for null int/null Date

    Heres the situation, there is an interface accepting an int value and a time/date that are not required(and are not set to anything automatically, i have no control over that part unfortunately), but I need to set up some sort of null/has value type of check to execute the setter when it does have a value, and ignore it when it doesnt. I am currently getting null pointers. here is my current set up:
    //throws null pointer as set up below, I am assuming I might want to eliminate the "getDate" off of the end and that might clear it up.
    if(data.getDate().getTime() != null)
              tempData.setDate(data.getDate().getTime());
    //Not sure on this one yet, the value doesn't get set to anything so I am assuming it automatically gets assigned something like -1.
    if(data.getId() >= 0){
              tempData.setId(data.getId());
              }

    tsdobbi wrote:
    I know data isnt null because it goes through a bunch of other tempData.set(data.get) items prior to hitting a snag on the above date I mentioned, when there is no value input for the date. and that particular null check I do there, does not work because it throws a null pointer in the if statement itself.
    i.e. it traces the null pointer to
    (if data.getDate().getTime != null) //this is the line the null pointer traces to.{color:#3D2B1F}if data is not null, then it must be the case that data.getDate() is null. Now that's what I call logic. W00t!{color}

  • Conversion from int to String

    How can i convert an int to a String.
    There is no direct String constructor that take only an integer.
    Thanks

    int num = 1;
    String str = "" + num;
    or
    int num = 1;
    String str = Integer.toString(num);

  • Check special characters in a string

    Hi all
    I am using oracle 10g.......
    Need to know what should be the query to check whether a special character exists or not in a column value....used the following query like.....
    select count(*) into emp_no_count_special_char
    from dual
    where REGEXP_LIKE(insert_data_rec.emp_no , '[#!$^&*%./\|]$' )
    or REGEXP_LIKE(insert_data_rec.emp_no , '^[#!$^&*%./\|]' );
    This works fine in case a string starts or ends with a special character ,what if a string of special characters lies in between numeric digits.
    e.g: '100#$%7'
    Please help find a query that checks for the existence of sp. characters irrespective of their position in the column!!!
    Thanks
    Dave
    Edited by: Dave on Jun 6, 2012 5:17 AM
    Edited by: Dave on Jun 6, 2012 5:18 AM

    Hi Dave,
    example below:
    -- Check that at least one special character exists in the string
    SELECT COUNT (*)
      INTO emp_no_count_special_char
      FROM DUAL
    WHERE REGEXP_LIKE (insert_data_rec.emp_no, '[#!$^&*%./\|]');
    -- Check that no special characters exist in the string
    SELECT COUNT (*)
      INTO emp_no_count_special_char
      FROM DUAL
    WHERE NOT REGEXP_LIKE (insert_data_rec.emp_no, '[#!$^&*%./\|]');
    {code}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Converting int to string, adding to string then pointing to an url

    So I'm getting a null pointer exception here's a snippet of my code (theres plus signs on both sides of the a in my code):
    private Image[] tiles;
    public Map() {
    for(int a=0; a<9; a++){
    ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares"+a+".png"));
    tiles[a] = aa.getImage();
    I've also tried:
    private Image[] tiles;
    public Map() {
    for(int a=0; a<9; a++){
    ImageIcon aa = new ImageIcon(this.getClass().getResource("mapsquares$s.png", String.valueOf(a)));
    tiles[a] = aa.getImage();
    whats wrong with either of these?
    Edited by: Wub on Feb 28, 2013 3:17 PM

    1.) You should use code tags when posting code.
    2.) You should read the stacktrace closely to find out which exact line number in your code threw the exception.
    My guess is that it's the line tiles[a] = aa.getImage(); because you didn't initialize the array tiles using the new operator. This is just a guess since you didn't post the full stacktrace. Also, NullpointerExceptions are one of the easiest to debug. Just adding print out lines at strategic values can show you which variables are initialized and which ones are not.

Maybe you are looking for

  • I bought 20 new songs in the ITunes store but they are not in my IPOD after synching?

    I bought 20 new songs in the ITunes store but they are not in my IPOD after synching?

  • Should have got another 3gs... iphone 4 has given me a head ache!

    Ok so I had an iphone 3gs, for 2 years and it was great! It died last week from a fall. So I decide to get an iphone4, 32 gig. So far, since I got it tonight, itunes has made me restore 4 times now. Not 3, but 4. Every time I get done, itunes shows t

  • JScrollPane bar alignment

    I posted this to ProjectSwing forum and never got a reply, maybe here someone knows... I tried all the suggested methods, and yet I still get the vertical scroll bar aligned somewhere in the middle when the JFrame opens, when top alignment would be p

  • GTX 970 HDMI Port

    Hi Guys, i'm wondering if the newly announced GTX970 from MSI has an HDMI 2.0 or HDMI 1.4a Port. The MSI Website states the latter, although the 'reference' model as well as some custom cards from other manufacturers having a HDMI 2.0 connection woul

  • SAP Business Workflow and The Workflow Reference Model

    Hi Experts, I try to map the Business Workflow with the Workflow Reference Model of WfMC. Interface 3 represents the communication of SAP's Workflow Engine with "Invoked (external) Applications". My Questions are: - which applications, tools can be i