lets say I have my owndefined datatype like this:
public class InformationType
{
private String brand;
private int number;
private double power;
public PurchaseInfo(String brand, int number, double power)
{
this.brand = brand;
this.number = number;
this.power = power;
}
public String getBrand()
{
return this.brand;
}
public int getNumber()
{
return this.number;
}
public double getPower()
{
return this.power;
}
}
then i have a program which prints strings that is either just a string, an int or a double, and i add them all to an array with the same type as my created one:
theInfo.add(new InformationType(theBrand, theNumber, thePower))
when I do a loop to just check if i got em right i just get pointers (i think its called) to them and not the real string/int/double. i want to print all my types, without using my getters. this is what i do:
for (InformationType x : theInfo)
{
System.out.println(x);
}
and i get stuff like InformationType@abcd12412413 etc..
and yeah, i made theInfo with:
ArrayList<InformationType> theInfo = new ArrayList<>();
thanks.
You need to override
toString. e.g.:This will now automatically get called by
println.