Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Converting String to Int with value validation

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Converting String to Int with value validation

    Hi. I'm new to java. I just wanted to know how do I

    • Convert String to Int. Also, I would like the conversion to produce and error if the data type is wrongly assign
    • Also, I would like the conversion to produce an error if the data type is wrongly assign. (Example: Assigning 'A' into integer, will be a disaster)


    So, how do i overcome this problem? Thank you.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Converting String to Int with value validation

    Hi and welcome to the forum ncode



    Convert String to Int. Also, I would like the conversion to produce and error if the data type is wrongly assign
    Your favorite search engine is the better place for a question so vague. The only way to answer that here is to break out a full lesson on the subject, or just post working code.



    Also, I would like the conversion to produce an error if the data type is wrongly assign.
    Didn't you just say that on the line above too?



    Do some research and post a question when you get stuck. Don't forget to include your code (in tags) and error messages.

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: Converting String to Int with value validation

    there is an Integer class called in java a wrapper class that converts a valid numerical String into a process-able integer number

    Integer (Java 2 Platform SE v1.4.2)

    you dont need to worry about monitoring if the String being parsed is valid/invalid, this class will throw you an exception if you attempt passing an invalid String number

  4. #4
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Converting String to Int with value validation

    Thx for reply. Ya. This question is a bit of vague. But anyway, chronoz13 provided me some guide. Thank you.

Similar Threads

  1. Converting a String to an Int? Is it possible?
    By Gravity Games in forum Java Theory & Questions
    Replies: 2
    Last Post: July 14th, 2012, 11:21 PM
  2. [SOLVED] Issue with converting a string to a date
    By dave_nj in forum What's Wrong With My Code?
    Replies: 15
    Last Post: May 2nd, 2012, 02:14 PM
  3. Help with code for converting 4 digit string to integer
    By danielp1213 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 24th, 2011, 09:38 PM
  4. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM
  5. Converting to String
    By darek9576 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 13th, 2010, 05:09 PM