difference between toString() and type casting a n Object to String

Discussion in 'Java' started by narsing, Oct 23, 2006.

  1. narsing

    narsing Guest

    what is the difference between toString() and type casting a n Object
    to String
     
    narsing, Oct 23, 2006
    #1
    1. Advertisements

  2. narsing

    Danno Guest

    Try it. Three lines is all it takes:

    Integer mynum = new Integer(4);
    System.out.println(mynum.toString());
    System.out.println((String) mynum);
     
    Danno, Oct 23, 2006
    #2
    1. Advertisements

  3. Thomas Weidenfeller, Oct 23, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.