#1
  1. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0

    Convert int --> String


    How would I convert an int to a String? I tried this code, but I get errors:
    Code:
    String new_day = day.toString();
    String new_year = year.toString();
    Code:
    An error occurred at line: 1 in the jsp file: /infra/software/database/calendar/holidays.jsp
    
    Generated servlet error:
        [javac] Compiling 1 source file
    
    C:\tomcat\work\Standalone\localhost\infosys\infra\software\database\calendar\index_jsp.java:408: int cannot be dereferenced
    String new_day = day.toString();
                        ^
    
    
    
    An error occurred at line: 1 in the jsp file: /infra/software/database/calendar/holidays.jsp
    
    Generated servlet error:
    C:\tomcat\work\Standalone\localhost\infosys\infra\software\database\calendar\index_jsp.java:409: int cannot be dereferenced
    String new_year = year.toString();
                          ^
    2 errors
  2. #2
  3. PHP & Java Error Master
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    My Computer
    Posts
    1,219
    Rep Power
    0
    Nevermind, found it:
    Code:
    String new_day = Integer.toString(day);
    String new_year = Integer.toString(year);
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Just for redundancy's sake, you can also use
    Code:
    String.valueOf(int)
  6. #4
  7. I played Richard the Third
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Den Haag, Netherlands
    Posts
    122
    Rep Power
    12
    if my memory serves me right. String.valueOf() is the better option because Inter.toString() generated an intermediate object to get the endresult.

    Could be wrong, though.
    Now is the winter of our discontent made glorious summer by this son of York.

IMN logo majestic logo threadwatch logo seochat tools logo