我有 3 个向量,如下所示。这里 Vector1、Vector2、Vector3 的大小不同。下面给出的是一种理想情况,只会发生一段时间。vector2 可能只包含一个额外的 {},d=3 ,... 和 vector1 和 Vector3 将没有那个 (d=3) 条目。
Vector1 := [{a=Prity, b=Joshi, c=Pyarelal, d=1},{a=tiny, b=darji, c=Mohandas, d=2}]
Vector2 := [{e=age-29, f=height-5, d=1},{e=age-52, f=height-6, d=2}]
Vector3 := [{g=pet-dog, d=1},{g=pet-cat, d=2}]
我想要一个将合并值并给我最终向量的向量,如下所示
Vector4 := [{a=Prity, b=Joshi, c=Pyarelal, d=1,e=age-29, f=height-5, g=pet-dog}, {a=tiny, b=darji, c=Mohandas, d=2, e=age-52, f=height-6, g=pet-cat}]
我实现了一个逻辑,但它很耗时。有没有人有更好的选择??????
int columnSize = Vector1.size() > Vector2.size() ? Vector1.size()
: Vector2.size();
Hashtable finalHash[] = new Hashtable[columnSize];
for (i = 0; i < Vector1.size(); i++) {
finalHash[i] = (Hashtable) Vector1.elementAt(i);
for (int z = 0; z < Vector2.size(); z++) {
Hashtable hashtwo = (Hashtable) Vector2.elementAt(z);
if (hashtwo.containsValue(finalHash[i]
.get("TQM_QUOTE_INCEPTION_DATE"))) {
finalHash[i].putAll(hashtwo);
Vector2.removeElementAt(z);
}
}
for (int z = 0; z < Vector3.size(); z++) {
Hashtable hashduerenew = (Hashtable) Vector3.elementAt(z);
if (hashduerenew.containsValue(finalHash[i]
.get("TQM_QUOTE_INCEPTION_DATE"))) {
finalHash[i].putAll(hashduerenew);
Vector3.removeElementAt(z);
}
}
}
columnSize = Vector2.size() > Vector3.size() ? Vector2.size() : Vector3
.size();
Hashtable finalHashtable = new Hashtable();
for (int t = 0; t < Vector2.size(); t++, i++) {
finalHashtable = (Hashtable) Vector2.elementAt(t);
for (int z = 0; z < Vector3.size(); z++) {
Hashtable hashtwo = (Hashtable) Vector3.elementAt(z);
if (hashtwo.containsValue(finalHashtable
.get("TQM_QUOTE_INCEPTION_DATE"))) {
finalHash[i].putAll(hashtwo);
Vector3.removeElementAt(z);
break;
}
}
finalHash[i].putAll(finalHashtable);
Vector2.removeElementAt(t);
}
int t = 0;
while (t < Vector3.size()) {
finalHash[i] = (Hashtable) Vector3.elementAt(t);
t++;
i++;
}