2017-09-28 1 views
3

アップルを追加するメソッドを作成しようとしています。リスト内の各リンゴオブジェクトには、そのリンゴ内の別々のリストが含まれています。私はちょうど混乱していると、この全体を壊す方法。ここで は、私はこのすべてのこのような何か試してみてください....アップルに追加する

public class CustomerDatabase { 
    private ArrayList<Customer> customerList = null; 

    public CustomerDatabase() { 
     customerList = new ArrayList<>(); 
    } 
} 
+0

をあなたはhttps://stackoverflow.com/questions/46458779/でこれに取り組んでいます追加文字列オブジェクト対arraylist –

答えて

1

を設定している方法は次のとおりです。

public void addProduct(String n, String p) 
{ 
    // loop though the Customers 
    for (Customer c : customerList) 
    { 
     // look for the one. i do not know what n is, assumed name from paramter n 
     if (n.equals(c.getName())) 
     { 
     // when found: 

     // add product to the wishlist, checking it is not on the list already 
     if (!c.getWishlist().contains(p)) 
      c.getWishlist().add(p); 
     // if adding order of the wishlist is not important, another collection type 
     // EG a Set, which can only hold a value once, might be useful... 

     // exit the method, without throwing exception 
     return; 
     } 
    } 
    // if the loop finished, no Customer was found, throw exception 
    throw new IllegalArgumentException(); 
} 
+0

おっと、ええ、私の悪い...編集中... –

関連する問題