其實這裏是一個arrayList,我希望它打印。但每當我收到錯誤。有人請幫助我。 class Product
在java中打印arraylist
List<Product> pd = new ArrayList<Product>();
pd.add(new Product("Trouser",40, 499,"Cotton", "Black"));
pd.add(new Product("Shirt",32, 999, "Cotton","White"));
pd.add(new Product("T-Shirt",32, 599 ,"Cotton","Blue"));
pd.add(new Product("Blazer",32, 1299 ,"Cotton","Brown"));
所以這是ArrayList的..我要打印出來。 我試過這種方式 -
public static void main(String [] ar)
{
Product pd = new product();
for(Object o : pd)
{
Product pd = (Product)o;
System.out.println(pd);
}
但它不工作。有人請幫忙。 注:主要方法也是類Product的一部分。
在此先感謝!
。而且它無助於你多次聲明'pd'變量。 – Eran
不工作是什麼意思?有什麼異常? – xyz
我不能一起打印字符串和整數嗎? – Darpanjbora