So, i am making an eshop in java, but I am facing a problem that I can't solve. The eshop sells 4 items, so we have the class Item and the subclasses Pen, Pencil, Notebook and Paper and I have stored them all in an arraylist. I want to make a method, which prints the products in categories according the type of the object that they are. For example: Pen -> pen1, pen2 Pencil-> pencil1,pencil2
The problem that I have is that I don't know how to recognise in the arraylist that for example pen1 is a pen object and print it at the pen category. I tried to use an iterator, but i am not very familiar with it, so i couldn't do much.