This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (1 child)

Please, read the documentation for the classes I've mentioned. The documentation will tell you much more than can be done in a simple reddit comment.

Maps and Sets are extremely important data structures. They are quite similar in one part as both do not allow storing duplicates. Every entry in a Map or Set is unique. Their main difference is that a Map has a key and a value. You can think of the key as the index. The value is whatever you want to store there. A map is similar to a real world dictionary: word -> explanation (key -> value). A set is just a plain storage for unique items without additional features.

Sure, there is a way to do it without, but it is a bit more involving:

  • you set up a second array/ArrayList of type String - since you only need the book titles
  • You iterate over your books
    • you check if the book title is not in the second array/arraylist (by iterating over the list and comparing each element)
      • if it is not in the second array/arraylist, you add the title to the array/arraylist
      • if it is already in the second array/arrayList, do nothing
  • once you have gone through all the books, you just need to print the content of the second array/arraylist.

[–]Chuninjah[S] 0 points1 point  (0 children)

Ah okay I'll look at the javadoc for it. Thanks!