我有一个具有以下结构的HashMap:
Map<Object, List<OtherObject>>
我想将其转换为:
List<FinalObject>
成为FinalObject:
public class FinalObject {
private Object object;
private List<OtherObject> otherObject;
}
答案 0 :(得分:7)
假设您有一个类似的构造函数:
public FinalObject(Object obj, List<OtherObject> list) {
this.object = obj;
this.otherObject = list;
}
然后您可以做:
List<FinalObject> newList = map.entrySet()
.stream().map(e -> new FinalObject(e.getKey(), e.getValue()))
.collect(Collectors.toList());
答案 1 :(得分:2)
相应的[0.8310797810554504, 0.14590543508529663, 0.013837042264640331, 0.005048676859587431, 0.0027143193874508142]
['petunia', 'pink primrose', 'balloon flower', 'hibiscus', 'tree mallow']
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-f54be68feb7a> in <module>()
12 flower_tensor_image = flower_tensor_image.unsqueeze_(0)
13
---> 14 axs = imshow(flower_tensor_image, ax = plt)
15 axs.axis('off')
16 axs.title(top5_class_names[0])
<ipython-input-15-9c543acc89cc> in imshow(image, ax, title)
5 # PyTorch tensors assume the color channel is the first dimension
6 # but matplotlib assumes is the third dimension
----> 7 image = image.transpose((1, 2, 0))
8
9 # Undo preprocessing
TypeError: transpose(): argument 'dim0' (position 1) must be int, not tuple
<matplotlib.figure.Figure at 0x7f5855792160>
方法是:
System.out.println("the program is outputing this");
if (ListBookMark.size() > 0) {
for (SomeObject bs : DictionaryVar.values()) {
System.out.println("working now");
if (jTable1.getModel().getColumnName(1).equalsIgnoreCase(bs.GetName()) == false) {
((DefaultTableModel) jTable1.getModel()).addRow(new Object[]{false, bs.GetName(), "", "", 0, ""});
}
}
}else {
System.out.println("bs size = " + (ListBookMark.size() ));
}