以下の関数は商品リストを返します。商品リストは一意である必要があります。
ベクター ServAttributes は、カスタム クラスのオブジェクトを格納します。カスタム クラスには、重複を含む可能性のある製品名を提供する関数 getProduct があります。
ベクター全体をスクロールし、オブジェクトを取得し、関数 getProduction を呼び出し、ハッシュ セットに追加して重複した製品を削除する必要がありますか? Vector にはカスタム クラスのオブジェクトが 400 個格納される場合があります。以下の機能を実行する簡単な方法はありますか?
private Vector<ServAttributes> ServAttributes = null;
public HashSet<String> retProduct() {
HashSet<String> Produset = new HashSet<String>();
for (int x = 0; x < ServAttributes.size(); x++) {
ServAttributes record = ServAttributes.get(x);
if (record.getProduct()) != null) {
Produset.add(record.getProduct());
}
return Produset;
}