Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable convertion

    how to convert from integer to string in java?

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    int i = 1;
    String s = Integer.toString(i);
    System.out.println(s);
    shmoove

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank u 4 your reply.
    but i have another question, if i want to view an integer number in a textfield, lets say i, must i convert it at first to string by using String s = Integer.toString(i), and then using the textField.setString(s) or there is another way?

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can skip the part where you put it into a String variable:
    Code:
    textField.setString(Integer.toString(i))
    shmoove

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, if i have three textFields, one of them displays the multiply of the others. how to convert the string to integer? and how to get the text in the textField?

  • #6
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know how to get the text from the textfield because I don't use J2SE (I'm guessing textfield.getString() though), but to convert the string back to an int you use the Integer.parseInt(String s) method.
    What you should really do is get the documentation for the classes you're using and read that. It probably has all the answers you need.

    shmoove

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry shmoove for bothering u, may be this question is the last one, where can i find the documentation for the classes?

  • #8
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's OK. It's no bother.
    Here you can find all the documentation. The API specs will be the most useful (API & Language section -> Java 2 Platform API Specification), and in your place I'd maybe try a few of the tutorials.

    shmoove


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •