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

Thread: char to int cov problem

  1. #1
    Member
    Join Date
    Jun 2011
    Posts
    68
    My Mood
    Cool
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default char to int cov problem

    I have thread name coming into ll

    Thread-99

    but for Thread-9 ,this conversion return errors :please suggest me a code to convert the name of thread to only INT type number

    String a=ll.substring(7,9);

    String ll=Thread.currentThread().getName();
    String a=ll.substring(7,9);
    int i = Integer.valueOf(a).intValue();


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: char to int cov problem

    Will the thread name always be in that format? You can find the index of the hyphen and substring from there to the end. Or you can use a regular expression to remove all non-digits chars.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: char to int cov problem

    By the way ll is a realy bad variable name. Is it 2 capital i's or capital i lowercase el or lowercase el capital i or 2 lowercase el's?

  4. #4
    Member OutputStream's Avatar
    Join Date
    Apr 2011
    Posts
    32
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 3 Posts

    Default Re: char to int cov problem

    edit: nvm, haven't had my coffe yet ^^
    Last edited by OutputStream; June 16th, 2011 at 11:36 AM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: char to int cov problem

    the second parameter is the length and not the index you wish to end at.
    Are you sure?
    When in doubt read the documentation.

  6. #6
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: char to int cov problem

    Quote Originally Posted by Norm View Post
    Are you sure?
    When in doubt read the documentation.
    Maybe Sun/Oracle have it wrong?

    "The substring begins at the specified beginIndex and extends to the character at index endIndex - 1".

Similar Threads

  1. char.toHexString();
    By SPACE MONKEY in forum What's Wrong With My Code?
    Replies: 16
    Last Post: February 28th, 2011, 08:46 AM
  2. converting int to char
    By surfbumb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 19th, 2011, 12:59 AM
  3. [SOLVED] Why do i need to take 48? char to int.
    By Scotty in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 29th, 2010, 10:23 PM
  4. char (toUppercase?)
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 12th, 2009, 10:01 AM
  5. Vietnamese Character Problem in JSP Report. Chinese and Thai Char OK
    By mrvora in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: October 23rd, 2009, 02:35 AM