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
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 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, 08: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, 10:08 PM
  4. BASE CONVERSION
    By bgwilf in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 13th, 2010, 12:02 PM
  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, 07:06 AM