I’m trying to insert different data types into linked list. The problem is that after I insert data I don’t know how to read values back when I display my data.
So how to retrieve the values in this kind of order:
List (first-->last): {brand1, 11,111}, {brand2, 22,222}
List (last-->first): {brand2, 22,222}, {brand1, 11,111}
The output I get represent name of the object and then address of the object:
List (first-->last): Milk@1f5205c Milk@1fb069
List (last-->first): Milk@1fb069 Milk@1f5205c
This is my object class:
class Milk <T>
{
String brand;
double size;
double price;
Milk(String a, double b, double c)
{
brand = a;
size = b;
price = c;
}
}
You need to override your Milk class’s
toStringmethod so that it uses a custom version instead of falling back onObject‘s implementation.In your case, this would probably be as easy as throwing this in to your
Milkclass.