Results 1 to 3 of 3
  1. #1
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

    Default String to Integer conversion

    I want to convert a string to integer. I wrote following code but it throws exception.

    Java Code:
    String str = "22";
    int a = (int)str;
    Exception:
    Java Code:
    Cannot cast from String to int
    Can anyone indicate the problem area?

    -PEACE

  2. #2
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    You can use the following lines of code

    String a = "123"
    int number = Integer.parseInt(a);

  3. #3
    eva
    eva is offline Member
    Join Date
    Dec 2007
    Posts
    49
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 03-25-2008, 12:16 PM
  2. bytearray to string conversion
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 10:39 AM
  3. Method for String to int conversion
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:35 PM
  4. How to cast an Object into a specific type (Integer/String) at runtime
    By mailtogagan@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 12-03-2007, 01:04 PM
  5. String to Date conversion
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 07:16 PM

Posting Permissions

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