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 2 of 2

Thread: Need help regarding String to int Conversion

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Need help regarding String to int Conversion

    in Java when we use parseInt(String) how can we chck that if the String has only the numbers, or it contains any character too. is there any sort of function or we have to chck every index separately ?



    Cross posted at:


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Need help regarding String to int Conversion

    Use a regular expression - the matches() method of the String class does just that. For example, to check for integer values, use "[0-9]+" or "[\\d]+"

    Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)

  3. The Following User Says Thank You to copeg For This Useful Post:

    fredsilvester93 (July 20th, 2012)

Similar Threads

  1. Help with conversion
    By TheEvilCouncil in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2012, 07:29 PM
  2. String and Bit Array conversion issues
    By GeekWarth in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 07:13 PM
  3. Conversion from multiple ints to single string
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 09:08 PM
  4. BASE CONVERSION
    By bgwilf in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 13th, 2010, 11:02 AM
  5. [SOLVED] utf-16 byte[] to string conversion
    By Gerhardl in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 25th, 2010, 06:06 AM