Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Java Linked List isn't displaying strings correctly

Main Class:
Spoiler (Click to View)
myHero Class:
Spoiler (Click to View)
When I add a hero to the list it adds correctly but when I display the list it doesn't print as the 2 strings but as some random characters with the class name.

Picture of what is happening:
i.imgur.com/PpFDf73.png
You do not override the toString() method. I think you attempted but misunderstood how.

PHP Code

<?php 
// current code
// toString is not supposed to have parameters. You're supposed to just use field references.
 
  public String toString(String name, String date)
 
  {
 
      return (name + "" + date);
 
  } 
PHP Code

<?php 
// correct code 
 
  @Override
   
public String toString()
 
  {
 
      return name + " " + date;
 
  } 
(Feb 3, 2018 01:53 PM)GenericSkid Wrote:  You do not override the toString() method. I think you attempted but misunderstood how.

PHP Code

<?php 
// current code
// toString is not supposed to have parameters. You're supposed to just use field references.
 
  public String toString(String name, String date)
 
  {
 
      return (name + "" + date);
 
  } 
PHP Code

<?php 
// correct code 
 
  @Override
   
public String toString()
 
  {
 
      return name + " " + date;
 
  } 

Thank you for fixing my silly mistake. 🤝


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pro_fesnoobSep 24, 2022 04:24 PM 14 797 Sep 24, 2022 04:24 PM
Last Post: BinaryFox
[.NET] by VUEDUEJan 8, 2022 09:54 AM 5 252 Jan 8, 2022 09:54 AM
Last Post: Luffy-_-
[C] by LynxJan 3, 2022 04:47 PM 1 184 Jan 3, 2022 04:47 PM
Last Post: yuumi