Results 1 to 3 of 3

Thread: using parse

  1. #1
    mustachMan is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Default using parse

    what does
    Double.parseDouble();
    and
    Integer.parseInt();
    do?
    I have seen it in code and looked it up in different places but i couldn't understand it

  2. #2
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Integer.parseInt(String s)

    It takes a String object as its parameter and makes it into an Integer object (Integer objects can be boxed into primitive data)
    Example:

    Java Code:
    String num = "523";
    int x = Integer.parseInt(num);
    It converted the string "523" into an Integer object which autoboxed it to an int primitive data. This is what happens when you do not parse:

    Java Code:
    String num = "523";
    int x = num;
    
    [COLOR="Red"]Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    	Type mismatch: cannot convert from String to int[/COLOR]
    The same thing goes for double.

    Java Code:
    String num = "523.23";
    double x = Double.parseDouble(num);
    It converted the string "523.23" into an Double object which autoboxed it to an int primitive data.
    Last edited by Lil_Aziz1; 01-15-2010 at 02:17 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  3. #3
    mustachMan is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

Similar Threads

  1. Ugly XML to parse
    By JohnST in forum New To Java
    Replies: 2
    Last Post: 01-03-2010, 05:48 PM
  2. How to parse a .db file ?
    By aminov in forum JDBC
    Replies: 0
    Last Post: 08-06-2009, 05:11 PM
  3. SAX Parse
    By bluefloyd8 in forum New To Java
    Replies: 1
    Last Post: 01-25-2008, 04:57 PM
  4. how to parse an xml file
    By oregon in forum XML
    Replies: 3
    Last Post: 08-01-2007, 05:53 PM
  5. How to parse in html
    By paty in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 01:29 AM

Posting Permissions

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