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

Thread: Can I use toString() here?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Can I use toString() here?

    I have this LinkedList called cardList. I have placed cards here using this:

    cardList.add(new Card(int suit, int rank))
    I can display the contents = 00, 01, 02 and so on ... with my suit being 0==Diamonds, 1 == Hearts, 2==Spades and 3==Clubs and the ranks are A, K, Q, J, 10 down to 2.

    How do I display the contents of this cardList to see AD,1D, 2D and so on?
    When I used toString(), the result was [[Ljava.lang.String;@1bc4459[Ljava.lang.String;@12b6651, ...


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Can I use toString() here?

    Quote Originally Posted by titowinky View Post
    I have this LinkedList called cardList. I have placed cards here using this:

    cardList.add(new Card(int suit, int rank))
    I can display the contents = 00, 01, 02 and so on ... with my suit being 0==Diamonds, 1 == Hearts, 2==Spades and 3==Clubs and the ranks are A, K, Q, J, 10 down to 2.

    How do I display the contents of this cardList to see AD,1D, 2D and so on?
    When I used toString(), the result was [[Ljava.lang.String;@1bc4459[Ljava.lang.String;@12b6651, ...
    Hello titowinky!
    The result you have is the default String that the toString() method (of your Card class I suppose) returns. If you want it to be different you need to override the toString() method of your Card class and return the String you want.
    Hope this helps.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,317
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Can I use toString() here?

    [[Ljava.lang.String;
    That is the toString() values for a two dim array of type String. The leading [s shows that the object is an array.

    Can you post the definition of the object that you are trying to print out?
    The Arrays class's toString() method will format array contents for printing or you many have to write some loops.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. toString method
    By pelane in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 23rd, 2012, 02:42 AM
  2. Can someone help me understand toString()?
    By Psychotron in forum Java Theory & Questions
    Replies: 10
    Last Post: January 18th, 2012, 10:43 PM
  3. Why cant I use toString() with vector?
    By tarkal in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 14th, 2011, 08:24 AM
  4. toString method
    By feldmanb700 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 17th, 2011, 10:20 PM
  5. [SOLVED] toString() method
    By chronoz13 in forum Object Oriented Programming
    Replies: 12
    Last Post: January 19th, 2010, 06:44 AM