数据集中的数据是否可以累加

s5s12a2a 2008-03-19 02:05:33
例如map,list,hashmap

这三个不知道是否能完成数据累加.

数据累加的意思就是,
比如说,我声明了一个map,里面又10列值.可是我又从数据库中读取了5列.这5列我还是用刚才声明的map去接受.现在我想让现在声明的这个map中又15列值,不知道怎么去实现.

这是调用2个各自的方法得到的数据.想一起累加起来.还有list或者hashmap不知道能不能实现这样的功能,有经验的说说看看...
...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hmsuccess 2008-03-19
  • 打赏
  • 举报
回复
同意,HashMao和Map都有putAll(Map<? extends K,? extends V> m)方法
其实,象这些集合类如ArrayList就相当于动态数组,
dracularking 2008-03-19
  • 打赏
  • 举报
回复
Map接口有个putAll(Map<? extends K,? extends V> t)方法
或逐个put
hmsuccess 2008-03-19
  • 打赏
  • 举报
回复

class hashmaptest
{
public static void main(String[] args)
{
HashMap register = new HashMap();
register.put("name","jingsp");
register.put("date","1996-8");
register.put("stuid","960515");
register.put("status","overS");
register.put("scrol","excellence");
register.put("lasttime","1999-9");
System.out.println(register);
System.out.println("-------------------");
Set s = register.entrySet();
System.out.println(s);
System.out.println("-------------------");
Iterator it = s.iterator();
while(it.hasNext())
{
Map.Entry map = ( Map.Entry)it.next();
System.out.print(map+"\t");
System.out.println("key:"+map.getKey()+"\tvalue:"+map.getValue());
}
}
}

fastunit 2008-03-19
  • 打赏
  • 举报
回复
可以用HashMap+ArrayList实现,最好重新包装成一个类,提供简单设值、取值的方法。
zang1 2008-03-19
  • 打赏
  • 举报
回复
collection中有个addAll(Collection c)方法看看满足否

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧