可以说我有我自己定义的数据类型,如下所示:
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;
}
}然后我有一个打印字符串的程序,它不是一个字符串,一个int或一个double,而是将它们全部添加到与我创建的相同类型的数组中:
theInfo.add(new InformationType(theBrand, theNumber, thePower))当我做一个循环来检查我是否有权利我只是得到指针(我认为它的名称)给他们,而不是真正的字符串/整数/双。我想打印我的所有类型,而不使用我的getters。这就是我所做的:
for (InformationType x : theInfo)
{
System.out.println(x);
}和我得到像InformationType @ abcd12412413等东西。
是的,我做了这个信息:
ArrayList theInfo = new ArrayList<>();谢谢。