Results 1 to 6 of 6
  1. #1
    JMAsterson is offline Member
    Join Date
    Mar 2012
    Posts
    55
    Rep Power
    0

    Default length() returns int but not double

    why does the length() method return and int but never a double? Which way would the most advantages? (length() using int or length using double). Thanks!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,315
    Blog Entries
    7
    Rep Power
    25

    Default Re: length() returns int but not double

    Quote Originally Posted by JMAsterson View Post
    why does the length() method return and int but never a double? Which way would the most advantages? (length() using int or length using double). Thanks!
    Have you ever seen a String with 3.14159 elements?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    JMAsterson is offline Member
    Join Date
    Mar 2012
    Posts
    55
    Rep Power
    0

    Default Re: length() returns int but not double

    no, I haven't. So then I guess part of it is that I'm wondering why using a decimal in a string could be an issue.

  4. #4
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    5

    Default Re: length() returns int but not double

    There is no point in returning a double because you're never going to see a String with a non integer number of elements.

  5. #5
    JMAsterson is offline Member
    Join Date
    Mar 2012
    Posts
    55
    Rep Power
    0

    Default Re: length() returns int but not double

    Thanks.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,315
    Blog Entries
    7
    Rep Power
    25

    Default Re: length() returns int but not double

    Quote Originally Posted by JMAsterson View Post
    no, I haven't. So then I guess part of it is that I'm wondering why using a decimal in a string could be an issue.
    A decimal in a String is just another character; e.g. the String "3.14159" is a String with seven characters, the second character is a decimal point character.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Difference between length() and length
    By mitra in forum New To Java
    Replies: 7
    Last Post: 07-28-2011, 12:46 AM
  2. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 11:40 AM
  3. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 02:51 PM
  4. Replies: 5
    Last Post: 03-21-2009, 10:32 PM
  5. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 09:39 AM

Posting Permissions

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