简体   繁体   English

如何更新列表中的数据 <? extends Map<String,?> &gt;

[英]How to update data in a List<? extends Map<String,?>>

I'm making use of a List<? extends Map<String,?>> 我正在使用List<? extends Map<String,?>> List<? extends Map<String,?>> that I populated with data. List<? extends Map<String,?>>了我用数据填充的List<? extends Map<String,?>>

cursor.moveToFirst();
while (cursor.getPosition() < cursor.getCount()) {
    item.put("ProdName",cursor.getString(2));
    item.put("ProdSize", cursor.getString(3));
    item.put("ProdPack",cursor.getString(4));
    item.put("OrdQty","0");

    //list.add(item);
    list.add(i, item);
    item = new HashMap<String,String>();    
    cursor.moveToNext();
    i = i + 1;
}

How do I update a value for example in the OrdQty field? 如何更新例如OrdQty字段中的值?

Looks like a very bad design to me. 在我看来,这是一个非常糟糕的设计。 Java's an object-oriented language. Java是一种面向对象的语言。 Why don't you provide a real contract and create Product and Order objects? 您为什么不提供真实的合同并创建产品和订单对象? Give Order a List of Products to maintain. 给订单提供要维护的产品清单。 What you're proposing is less self-explanatory and harder to write and maintain. 您提出的建议不那么自解释,更难编写和维护。

@Duffymo is right, you shouldn't use a map as a pseudo-object. @Duffymo是正确的,您不应该将地图用作伪对象。

This is how to update an object at a specific place ( index ) in a list. 这是在列表中特定位置( index )更新对象的方法。

Map<String,?> ugly = list.get(index);

Then you can do whatever you want with the object ugly. 然后,您可以对对象进行丑陋的处理。

If you did it properly, it would look like this... 如果做得正确,它将看起来像这样...

Product p = list.get(index);
p.setOrderQuantity(17);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用List <? extends Map<String, ?> &gt; - How to use List<? extends Map<String, ?>> 地图 <String, List<? extends AbstractType> &gt; - Map<String, List<? extends AbstractType>> List <Map <String,String >> vs List <?扩展Map <String,String >> - List<Map<String, String>> vs List<? extends Map<String, String>> Java泛型放在地图上 <String, ? extends List<String> &gt; - Java Generics putting on Map<String, ? extends List<String>> Map <string, list<? extends object> &gt; Stream API 的过滤问题</string,> - Map<String, List<? extends Object>> filtering issue with Stream API 如何转换 Map <string, map<metricname, ? extends metric> &gt; 进入 JsonObject</string,> - How to convert Map<String, Map<MetricName, ? extends Metric>> into JsonObject 带通配符的泛型(地图 <? extends A, List<? extends B> &gt;) - Generics with Wildcards (Map<? extends A, List<? extends B>>) 自定义视图布局-“列表 <Map> 无法转换为列表 <? extends Map<String,?> &gt;” - Custom View Layout - “ List<Map> cannot be converted to List<? extends Map<String,?>> ” 如何构造地图 <String, List<String> &gt; Spring中的数据结构 - How to construct Map<String, List<String>> data structure in Spring 如何以地图形式获取数据<String, List<String> &gt; 使用单个查询? - How to get data as a Map<String, List<String>> using a single query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM