Hi, I'm new to Java and programming. I have an assignment I'm trying to do and I'm pretty stumped on this question.
I have a TreeMap where the keys are Strings (of musical artists) and the values are Lists (of artist name, album title, album genre and album year).
I have a method to do that display all information for every CD which I have iterated through with a foreach loop. The problem is that I can't get the List values to display all the information when I print, I just get the hash values? of each list bu I need it to print the information in the list. eg. The Sex Pistols, Nevermind the Bollox, Punk, 1977.
Can anyone tell me how to do that?
Jump to Post
This isn't very clear - but do you mean that those details are fields of a class you defined (eg Album) and when you print it you get some hex?
If so, that's the default toString() method that your class has inherited from Object, and what you need to do …
Jump to Post
CD@21e605 is what you get from the inherited toString() method - ie object type + pointer. Add a
public String toString()
method in your CD class and what it returns is what will automatically be used when the system wants to print a CD.
You don't really need printString once …
All 7 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.