Shop OBEX P1 Docs P2 Docs Learn Events
another question — Parallax Forums

another question

basicstampedebasicstampede Posts: 214
edited 2006-10-27 19:43 in General Discussion
Hello.· On pg. 57 of Javelin manual 1.0, there is a statement

System.out.println(String.valueOf(dischargeTime));

But nowhere do I see what String or valueOf does.· I can sort of figure it out, but I'm looking for some official statement of what this statement does.

Can anyone help please?

dischargeTime·was previously declared as

static int dischargeTime;
static int chargeTime;

By the way, this example declares chargeTime, but never uses it.· Any idea why not?

Thanks.

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-27 19:18
    The String class has a method valueOf() that takes an int and generates
    a string representing the signed decimal value of the int. So -4 generates "-4"
    Basically, it does Format.sprintf(buf,"%d",value).
    The advantage of Format, is that you can use binary, octal, decimal, unsigned decimal and·hex
    as the base for the generated string. Using Format.bprintf() you can even assemble strings
    in the same char array.

    regards peter
  • basicstampedebasicstampede Posts: 214
    edited 2006-10-27 19:30
    Peter, thanks.· How would I have learned about that if it wasn't for this forum?· i.e. is that info. in the Javelin manual somwhere?
  • basicstampedebasicstampede Posts: 214
    edited 2006-10-27 19:38
    What is valueOf?· I guess that is a method belonging to class String?

    Then what is String?· Is that a class?· Does it belong to System class?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-27 19:43
    On page 152/153 you will find a description of the class String.
    (You can search for valueOf in acrobat reader to find all references).
    It also states the method valueOf(int) generates a temporary string
    that usually is discarded once used. That may lead to out of memory error
    if one is not careful.

    The Format class does not have that problem at all. Because the Format
    class is not part of the Javelin IDE distribution, it is not discussed in the manual.
    That applies to all classes that Javelin users have developed.

    regards peter
Sign In or Register to comment.